#region //获取当前周几 private readonly string _strWorkingDayAm = "08:30";//工作时间上午08:00 private readonly string _strWorkingDayPm = "17:30"; private readonly string _strRestDay = "6,7";//周几休息日 周六周日为 6,7 private TimeSpan _dspWorkingDayAm;//工作时间上午08:00 private TimeSpan _dspWorkingDayPm; private string m_GetWeekNow() { string strWeek = DateTime.Now.DayOfWeek.ToString(); switch (strWeek) { case "Monday": return "1"; case "Tuesday": return "2"; case "Wednesday": return "3"; case "Thursday": return "4"; case "Friday": return "5"; case "Saturday": return "6"; case "Sunday": return "7"; } return "0"; } /// <summary> /// 判断是否在工作日内 /// </summary> /// <returns></returns> private bool m_IsWorkingDay() { string strWeekNow = this.m_GetWeekNow();//当前周几 ////判断是否有休息日 string[] RestDay = _strRestDay.Split(','); if (RestDay.Contains(strWeekNow)) { return false; } //判断当前时间是否在工作时间段内 _dspWorkingDayAm = DateTime.Parse(_strWorkingDayAm).TimeOfDay; _dspWorkingDayPm = DateTime.Parse(_strWorkingDayPm).TimeOfDay; TimeSpan dspNow = DateTime.Now.TimeOfDay; if (dspNow > _dspWorkingDayAm && dspNow < _dspWorkingDayPm) { return true; } return false; } #endregion