你如何找到一个月的最后一天? [英] How do you find the last day of the month?

查看:197
本文介绍了你如何找到一个月的最后一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何获取一个月的最后一天?

到目前为止,我有这样的:

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...)

这篇关于你如何找到一个月的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆