• c# 判断时间是否在 某一时间段内


    1.判断时间是否在某一时间段内

    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;
    }

    测试

    protected string getResult=string.Empty;
            protected void Page_Load(object sender, EventArgs e)
            {
                string time1 = "2017-2-17 9:45:00";
                //DateTime t1 = Convert.ToDateTime(time1);
                bool resultBool = getTimeSpan(time1);
                getResult = Convert.ToString(resultBool);
            }

    结果:

    测试有效果

  • 相关阅读:
    fedora 27
    Python3 字符串操作
    python3 使用matplotlib画图问题
    Python3 移动文件——合集
    MySQL开放外部链接
    python之csv操作问题
    Question
    17-12-21
    python之List排序
    ubuntu版的sublime-text3输入中文问题
  • 原文地址:https://www.cnblogs.com/wangfuyou/p/6410184.html
Copyright © 2020-2023  润新知