标签:
1 /// <summary> 2 /// 判断程序是否在设置运行时间内 3 /// </summary> 4 /// <param name="startTime">开始执行时间</param> 5 /// <param name="overTime">执行结束时间</param> 6 /// <returns>true:在执行时间内,false:在执行时间外</returns> 7 private bool IsRunTime(string startTime, string overTime) 8 { 9 var flag = false; 10 11 var beginTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + startTime); 12 var endTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + overTime); 13 14 if (beginTime <= endTime) // 当天 15 { 16 flag = beginTime <= DateTime.Now && DateTime.Now <= endTime; 17 } 18 else // 跨天 19 { 20 var zeroTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00"); 21 flag = (beginTime <= DateTime.Now && DateTime.Now <= zeroTime.AddDays(1)) || (zeroTime <= DateTime.Now && DateTime.Now <= endTime); 22 } 23 24 return flag; 25 }
标签:
原文地址:http://www.cnblogs.com/elliot-lei/p/5328954.html