C#获取月份的天数
更新:HHH   时间:2023-1-7


方法一://最有含量的一种

 
  1. int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month); 
 
 
方法二://最奇怪的一种
 
  1. DateTime dtNow = DateTime.Today; 
  2. int days = dtNow.AddDays(1 - dtNow.Day).AddMonths(1).AddDays(-1).Day; 
 
 
方法三://最常规的一种
 
  1. DateTime dtNow = DateTime.Now; 
  2. int days = DateTime.DaysInMonth(dtNow.Year, dtNow.Month); 

 

返回编程语言教程...