• 格式化日期时间 计算时间差


    /// <summary>
            /// 格式化日期时间
            /// </summary>
            /// <param name="dateTime1">日期时间</param>
            /// <param name="dateMode">显示模式</param>
            /// <returns>0-9种模式的日期</returns>
            public static string FormatDate(DateTime dateTime1, string dateMode)
            {
                switch (dateMode)
                {
                    case "0":
                        return dateTime1.ToString("yyyy-MM-dd");
                    case "1":
                        return dateTime1.ToString("yyyy-MM-dd HH:mm:ss");
                    case "2":
                        return dateTime1.ToString("yyyy/MM/dd");
                    case "3":
                        return dateTime1.ToString("yyyy年MM月dd日");
                    case "4":
                        return dateTime1.ToString("MM-dd");
                    case "5":
                        return dateTime1.ToString("MM/dd");
                    case "6":
                        return dateTime1.ToString("MM月dd日");
                    case "7":
                        return dateTime1.ToString("yyyy-MM");
                    case "8":
                        return dateTime1.ToString("yyyy/MM");
                    case "9":
                        return dateTime1.ToString("yyyy年MM月");
                    default:
                        return dateTime1.ToString();
                }


     /// <summary>
            /// 计算时间差
            /// </summary>
            /// <param name="DateTime1">时间1</param>
            /// <param name="DateTime2">时间2</param>
            /// <returns></returns>
            public static double DateDiff(DateTime DateTime1, DateTime DateTime2)
            {
                double dateDiff = 0;
                try
                {
                    TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
                    TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
                    TimeSpan ts = ts1.Subtract(ts2).Duration();
                    dateDiff = ts.TotalSeconds;
                }
                catch
                {
    
                }
                return dateDiff;
            }
    

      

      

  • 相关阅读:
    java笔记之IO详解——序列流
    java笔记之IO详解——输出字符流
    java笔记之IO详解——输入字符流
    java笔记之IO详解——输出字节流
    Nginx同一个域名部署多个项目
    服务器安装mongo数据库
    服务器安装node
    服务器Nginx配置及文件目录
    笔记 [待整理]
    vue-cli3打包app物理按键失效的问题[已解决]
  • 原文地址:https://www.cnblogs.com/dandanwozhishidan/p/3723590.html
Copyright © 2020-2023  润新知