Last day of the month in .NET

后端 未结 5 1682
闹比i
闹比i 2020-12-30 20:12

Normally I use the below code, but is there a better way?

lastOfMonth = new DateTime(Now.Year, Now.Month, 1).AddMonths(1).AddDays(-1)
5条回答
  •  被撕碎了的回忆
    2020-12-30 20:36

    I use

    DateTime now = DateTime.Today;
    var lastDate = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month));
    

提交回复
热议问题