How can I check if the current time is between in a time frame?

后端 未结 4 528
猫巷女王i
猫巷女王i 2020-12-02 15:50

I have a service that user can configure to run during \"off-peak\" hours. They have the ability to set the time frame that the service can run.

For Example:

4条回答
  •  一整个雨季
    2020-12-02 16:30

    DateTime t1;
    t1 = DateTime.Now;
    
    // loop inbetween start and end time      
    
    if (t1>=start_time &&t1<=end_time) 
    
    {
       //your code / action
    }
    
    //if you are using sql to get values 
    
    start_time = Convert.ToDateTime(row.Cells[10].Text);
    end_time = Convert.ToDateTime(row.Cells[11].Text);
    //convert them to string or you will get some error!!!
    

提交回复
热议问题