开发者

C# DateTime.AddMonth with day non-existent in next month

If I have DateTime date = new DateTime("1/31/2010"); and I cal开发者_如何学Gol date.AddMonth(1). Will I get "2/28/2010" or will it freak out because "2/31/2010" doesn't exist? Or will I get "3/3/2010"?

(Also I'm not near a computer with Visual Studio)


  • DateTime.AddMonths Method

If the resulting day is not a valid day in the resulting month, the last valid day of the resulting month is used. For example, March 31st + 1 month = April 30th.


You'll get the end day of the next month, so 2/28.


It will do a proper DateTime month addition and return 2/28/2010


It will not break, it will give you 2/28/2010

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜