//system date or any date u want this case it is a calendar picker - 22/03/2016
DateTime today = dtpFrom.Value;
//Add a month to your date example , it now becomes - 22/04/2016
DateTime endOfMonth = new DateTime(today.Year, today.Month,today.Day).AddMonths(1);
//Get the last date off the above which is - 30
int getlastday = DateTime.DaysInMonth(endOfMonth.Year, endOfMonth.Month);
//Now set the date to the value which will be the last day off the next month - 30/04/2016
DateTime newDate = new DateTime(endOfMonth.Year, endOfMonth.Month, getlastday);
5 回答
演示:http://rextester.com/AKDI52378
@本:
DateTime.Now.AddMonths(1)
将1
月添加到当前日期不减去11
个月 .DateTime.Now.AddMonths(1).Year
将给出2016
而不是2015
参考附图试试这个: