private bool getTimeSpan(string timeStr) { string[] dayTime = timeStr.Split('-'); //判断当前时间是否在工作时间段内 string _strWorkingDayAM = dayTime[0];//工作时间上午08:30 string _strWorkingDayPM = dayTime[1];//工作时间下午13:10 TimeSpan dspWorkingDayAM = DateTime.Parse(_strWorkingDayAM).TimeOfDay; TimeSpan dspWorkingDayPM = DateTime.Parse(_strWorkingDayPM).TimeOfDay; DateTime t1 = DateTime.Now; TimeSpan dspNow = t1.TimeOfDay; if (dspNow > dspWorkingDayAM && dspNow < dspWorkingDayPM)//在范围内返回true { return true; } return false; }