I'm trying to get the number of days in a month. So I have the following
var fromdate = LocalDateTime.FromDateTime(DateTime.Now).Date;
Now I just need the number of days in that LocalDateTime variable that I just created. It seems like I could enter:
var m = fromdate.Calendar.GetDaysInMonth(year, month)
But I already know the year/month in fromdate
. What is it that I'm doing wrong?
您可以使用 DateTime 的 GetDaysInMonth 方法:
int days = DateTime.DaysInMonth(year, month);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.