你如何找到一个月的最后一天?
问题描述:
可能重复:
如何获取一个月的最后一天?
到目前为止,我有这样的:
So far, I have this:
DateTime createDate = new DateTime(year, month, 1).AddMonths(1).AddDays(-1);
有没有更好的方法?
答
如何使用 DaysInMonth
:
DateTime createDate = new DateTime (year, month,
DateTime.DaysInMonth(year, month));
(请注意,在 Noda Time ...)
(Note to self - must make this easy in Noda Time...)