在C#中添加DateTime

im *_*ess 5 c# string int datetime

是否可以在C#中添加日期?

(DateTime.Today.ToLongDateString() + 10)
Run Code Online (Sandbox Code Playgroud)

我试过这个,但它不起作用.

Rvd*_*vdK 15

你想加几天吗?

DateTime newDate = DateTime.Today.AddDays(10);
Run Code Online (Sandbox Code Playgroud)

请注意,您将获得新的DateTime!

MSDN


Wil*_*l A 9

DateTime.Today.AddDays(10)在DateTime上使用或任何其他AddXXX函数.


Ric*_*der 8

什么是10的单位.如果是几天; 然后

var todayPlus10Days = DateTime.Today.AddDays(10);
Run Code Online (Sandbox Code Playgroud)


Val*_*ale 7

使用AddDays()方法:

DateTime dt = DateTime.Today;
dt = dt.AddDays(10);
Run Code Online (Sandbox Code Playgroud)