博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2010-10-12 22:55  moss_tan_jun  阅读(536)  评论(0编辑  收藏  举报

 

 

 

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

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;

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

DateTime dtNow = DateTime.Now;     int days = DateTime.DaysInMonth(dtNow.Year ,dtNow.Month);