1 /// <summary>2 ///Determine if the program is in set run time3 /// </summary>4 /// <param name= "StartTime" >Start Execution Time</param>5 /// <param name= "Overtime" >Execution End Time</param>6 /// <returns>true: Within execution time, false: Outside execution time</returns>7 Private BOOLIsruntime (stringStartTime,stringovertime)8 {9 varFlag =false;Ten One varBeginTime = Convert.todatetime (DateTime.Now.ToString ("YYYY-MM-DD") +" "+startTime); A varEndTime = Convert.todatetime (DateTime.Now.ToString ("YYYY-MM-DD") +" "+overtime); - - if(BeginTime <= EndTime)//Day the { -Flag = BeginTime <= datetime.now && datetime.now <=EndTime; - } - Else //Cross-day + { - varZerotime = Convert.todatetime (DateTime.Now.ToString ("YYYY-MM-DD") +"00:00"); +Flag = (beginTime <= datetime.now && datetime.now <= zerotime.adddays (1)) || (Zerotime <= datetime.now && datetime.now <=endTime); A } at - returnFlag; -}
The Windows service runs periodically to determine whether the current time is within the configured time period