1、获得当月有多少天
int m = System.DateTime.DaysInMonth(System.DateTime.Now.Year, System.DateTime.Now.Month);
2、日期型格式处理通用方法
(1)在global.asax中
protected void Application_BeginRequest(Object sender, EventArgs e) { Thread currentThread = Thread.CurrentThread; CultureInfo cul = currentThread.CurrentCulture.Clone() as CultureInfo; cul.DateTimeFormat.ShortDatePattern= BLLFacade.Common.GetShortDatePattern(); cul.DateTimeFormat.LongDatePattern= BLLFacade.Common.GetLongDatePattern(); cul.DateTimeFormat.ShortTimePattern= BLLFacade.Common.GetShortTimePattern(); cul.DateTimeFormat.LongTimePattern= BLLFacade.Common.GetLongTimePattern(); currentThread.CurrentCulture = cul; }
(2)在webconfig中配置如下
<add key="ShortDatePattern" value="MM-dd-yyyy" /> <add key="LongDatePattern" value="dddd-MMMM dd-yyyy" /> <add key="ShortTimePattern" value="hh:mm tt" /> <add key="LongTimePattern" value="hh:mm tt" />
(3)在业务逻辑层中
public static string GetShortDatePattern() { return System.Configuration.ConfigurationSettings.AppSettings["ShortDatePattern"]; } public static string GetLongDatePattern() { return System.Configuration.ConfigurationSettings.AppSettings["LongDatePattern"]; } public static string GetShortTimePattern() { return System.Configuration.ConfigurationSettings.AppSettings["ShortTimePattern"]; } public static string GetLongTimePattern() { return System.Configuration.ConfigurationSettings.AppSettings["LongTimePattern"]; }