获得当月有多少天及日期型格式处理通用方法

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"];
}

 

 

posted @ 2012-08-24 16:09  五度苍穹  阅读(337)  评论(0编辑  收藏  举报