判断时间点是否在工作日时间段区间内
Posted Blogger
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断时间点是否在工作日时间段区间内相关的知识,希望对你有一定的参考价值。
#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
以上是关于判断时间点是否在工作日时间段区间内的主要内容,如果未能解决你的问题,请参考以下文章