国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

獲得當(dāng)月有多少天及日期型格式處理通用方法

2023-05-05 19:01:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文給出了在C#中獲得當(dāng)月天數(shù)及常用的日期型格式處理方法。

1、如何獲得當(dāng)月有多少天

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)在業(yè)務(wù)邏輯層中

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

然后在其他地方正常調(diào)用就可以了,如果需要修改格式只需要修改webconfig中的,且可以保證整個(gè)系統(tǒng)中的所有格式都是一致的。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 麻城市| 娱乐| 高清| 德钦县| 东乌| 肥城市| 洛浦县| 保康县| 盐边县| 龙里县| 民乐县| 洛扎县| 织金县| 博客| 墨脱县| 正阳县| 巴马| 云安县| 铁岭县| 黄龙县| 安达市| 来宾市| 清河县| 广水市| 通河县| 永仁县| 四子王旗| 乐至县| 大兴区| 绥芬河市| 孟州市| 凤山县| 荥经县| 铜梁县| 元谋县| 板桥市| 温宿县| 高邮市| 张家界市| 仪征市| 广州市|