我试图在C#中使用DateTime函数来计算下个月的最后一天.
例如,今天是2015年12月17日.我希望DateTime函数返回2016年1月31日(下个月的最后一天).
我使用以下来计算下个月的第一天(这是有效的):
DateTime firstDayNextMonth = DateTime.Today.AddDays(-DateTime.Now.Day+1).AddMonths(1);
Run Code Online (Sandbox Code Playgroud)
Ben*_*igt 11
DateTime reference = DateTime.Now;
DateTime firstDayThisMonth = new DateTime(reference.Year, reference.Month, 1);
DateTime firstDayPlusTwoMonths = firstDayThisMonth.AddMonths(2);
DateTime lastDayNextMonth = firstDayPlusTwoMonths.AddDays(-1);
DateTime endOfLastDayNextMonth = firstDayPlusTwoMonths.AddTicks(-1);
Run Code Online (Sandbox Code Playgroud)
演示:http://rextester.com/AKDI52378
| 归档时间: |
|
| 查看次数: |
3067 次 |
| 最近记录: |