开发者

Adding days to a DateTime in C#

开发者 https://www.devze.com 2023-03-07 19:02 出处:网络
Is it possible to a开发者_如何转开发dd datesin C#? (DateTime.Today.ToLongDateString() + 10) I tried this but it doesn\'t work.Do you want to add days?

Is it possible to a开发者_如何转开发dd dates in C#?

(DateTime.Today.ToLongDateString() + 10)

I tried this but it doesn't work.


Do you want to add days?

DateTime newDate = DateTime.Today.AddDays(10);

Note that you get a new DateTime back!

MSDN


Use DateTime.Today.AddDays(10) or any of the other AddXXX functions on DateTime.


What is the unit of 10. If it is days; then

var todayPlus10Days = DateTime.Today.AddDays(10);


Use AddDays() method:

DateTime dt = DateTime.Today;
dt = dt.AddDays(10);
0

精彩评论

暂无评论...
验证码 换一张
取 消