zoukankan      html  css  js  c++  java
  • C# 时间对比

            public bool IfTime(string StartTime, string EndTime)
            {
                DateTime dt1 = Convert.ToDateTime(StartTime);
                DateTime dt2 = Convert.ToDateTime(EndTime);
                if (DateTime.Compare(dt1, dt2) < 0)
                {
                    //开始时间 < 结束时间 (执行以下语句),,说明开始时间晚
                    return true;
                }
                return false;
            }
    starttime= DateTime.Now.ToShortTimeString().ToString();
    
    
    

    public int Time_Minute_diff(string StartTime, string EndTime)
    {
    DateTime dt1 = Convert.ToDateTime(StartTime);
    DateTime dt2 = Convert.ToDateTime(EndTime);
    return dt1.Minute - dt2.Minute;
    }

     
     /// <summary>
            /// 获得固定年月日,时和分不固定 : 2019-01-01 00:00:00
            /// </summary>
            /// <returns></returns>
            public DateTime GetFixedDateTime()
            {
                string time1 = DateTime.Now.ToShortTimeString(); //16:50
                //yyyy-MM-dd hh:mm:ss //2019-01-01 16:34:00
                string Ymd = "2019-01-01 ";
                string Hour = DateTime.Now.Hour.ToString();
                string Minute = DateTime.Now.Minute.ToString();
                return Convert.ToDateTime(Ymd + Hour + ":" + Minute + ":" + 00);
            }
    
    
    
            /// <summary>
            /// 获得固定年月日,时和分不固定 : 2019-01-01 00:00:00
            /// </summary>
            /// <returns></returns>
            public DateTime GetFixedDateTime(string Hour = "", string Minute = "")
            {
                string time1 = DateTime.Now.ToShortTimeString(); //16:50
                //yyyy-MM-dd hh:mm:ss //2019-01-01 16:34:00
                string Ymd = "2019-01-01 ";
                if (Hour == "")
                {
                    Hour = DateTime.Now.Hour.ToString();
                    Minute = DateTime.Now.Minute.ToString();
                }
                return Convert.ToDateTime(Ymd + Hour + ":" + Minute + ":" + 00);
            }
    
    
  • 相关阅读:
    说说那些低级错误
    vue双向数据绑定
    妙用$.extend
    写一个限制执行次数的函数
    强类型语言不好的地方,比如这样:
    form表单里的坑
    Java Day 09
    Java Day 08
    Java Day 07
    Java Day 06
  • 原文地址:https://www.cnblogs.com/enych/p/9990386.html
Copyright © 2011-2022 走看看