zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C#获取当前月份天数的三种方法总结

c#方法 获取 总结 当前 三种 月份 天数
2023-06-13 09:15:16 时间

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

intdays=System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year,DateTime.Now.Month); 

方法二://最奇怪的一种

DateTimedtNow=DateTime.Today;    intdays=dtNow.AddDays(1-dtNow.Day).AddMonths(1).AddDays(-1).Day;

方法三://最常规的一种

DateTimedtNow=DateTime.Now;    intdays=DateTime.DaysInMonth(dtNow.Year,dtNow.Month);