js判断当前时间是否在指定区间之内,具体代码如下:
复制代码function timeCompare(nowTime, startTime, endTime) {
const s = startTime > endTime;
if (s) [startTime, endTime] = [endTime, startTime];
if (nowTime > startTime && nowTime < endTime) {
return s ? false : true;
} else {
return s ? true : false;
}
}
//输出结果:
const nowTime = '09:40:12'
const startTime = '08:30:00'
const endTime = '12:00:00'
console.log(timeCompare(nowTime, startTime, endTime)) //在区间内true,否则false
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
上面是“js判断当前时间是否在指定区间之内”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3485.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!