快速表达任何人都可以吗?
答案 0 :(得分:55)
var now = DateTime.Now;
var firstDayCurrentMonth = new DateTime(now.Year, now.Month, 1);
var lastDayLastMonth = firstDayCurrentMonth.AddDays(-1);
答案 1 :(得分:15)
DateTime now = DateTime.Now;
DateTime lastDayOfLastMonth = now.Date.AddDays(-now.Day);
答案 2 :(得分:3)
尝试DateTime.DaysInMonth(int year, int month) method
以下是一个例子:
DateTime oneMonthAgo = DateTime.Now.AddMonths(-1);
int days = DateTime.DaysInMonth(oneMonthAgo.Year, oneMonthAgo.Month);