.net 獲取當(dāng)前月份天數(shù)的幾種實(shí)現(xiàn)方法

字號(hào):


    方法一: //最具有技術(shù)含量的一種
    int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year ,DateTime.Now.Month);
    方法二://最奇怪的一種
    DateTime dtNow = DateTime.Today;
    int days = dtNow .AddDays(1 - dtNow .Day).AddMonths(1).AddDays(-1).Day;
    方法三://最常規(guī)的寫法
    DateTime dtNow = DateTime.Now; int days = DateTime.DaysInMonth(dtNow.Year ,dtNow.Month);