1. 程式人生 > >c# 判斷時間是否在 某一時間段內

c# 判斷時間是否在 某一時間段內

複製程式碼
protected bool getTimeSpan(string timeStr)
{ 
    //判斷當前時間是否在工作時間段內
    string _strWorkingDayAM = "08:30";//工作時間上午08:30
    string _strWorkingDayPM = "17:30";
    TimeSpan dspWorkingDayAM = DateTime.Parse(_strWorkingDayAM).TimeOfDay;
    TimeSpan dspWorkingDayPM = DateTime.Parse(_strWorkingDayPM).TimeOfDay;

    
//string time1 = "2017-2-17 8:10:00"; DateTime t1 = Convert.ToDateTime(timeStr); TimeSpan dspNow = t1.TimeOfDay; if (dspNow > dspWorkingDayAM && dspNow < dspWorkingDayPM) { return true; } return false; }
複製程式碼