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


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

     

  • 相关阅读:
    Ubuntu 20.04下EasyConnect兼容性问题临时解决方案
    Ubuntu 20.04 LTS安装搜狗输入法,只需三条命令,还能自动更新
    Java笔记: 继承成员覆盖和隐藏
    Java扫雷游戏: JMine
    Emacs: 设置窗口标题格式
    Java笔记: protected的真正含义
    Java笔记: 初始化块
    Ubuntu跨版本安装软件
    百度编辑器 Ueditor 增加字体
    AspCms 升级百度编辑器
  • 原文地址:https://www.cnblogs.com/qiufuwu618/p/2654390.html
Copyright © 2020-2023  润新知