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); }