JS判断当前时间是否在某个时间段内
代码】JS判断当前时间是否在某个时间段内。
·
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试时间</title>
</head>
<body>
<div>测试时间</div>
</body>
<script type="text/javascript">
// 判断现在时间班次
var date = {
isDuringDate: function (beginDateStr, endDateStr) {
var curDate = new Date(),
beginDate = new Date(beginDateStr),
endDate = new Date(endDateStr);
if (curDate >= beginDate && curDate <= endDate) {
return true;
}
return false;
}
}
var timetext= ""
if (date.isDuringDate('2022-08-10' + ' 00:00', '2022-08-10' + ' 09:00') == true){
timetext= "早上"
console.log("是否在区间:"+ date.isDuringDate('2022-08-10' + ' 00:00', '2022-08-10' + ' 09:00') + ";时间:" + timetext)
}else if (date.isDuringDate('2022-08-10' + ' 09:00', '2022-08-10' + ' 17:30') == true){
timetext = "下午"
console.log("是否在区间:"+ date.isDuringDate('2022-08-10' + ' 09:00', '2022-08-10' + ' 17:30') + ";时间:" + timetext)
}else if (date.isDuringDate('2022-08-10' + ' 17:30', '2022-08-10' + ' 00:00') == true){
timetext = "晚上"
console.log("是否在区间:"+ date.isDuringDate('2022-08-10' + ' 17:30', '2022-08-10' + ' 00:00') + ";时间:" + timetext)
}
</script>
</html>
更多推荐
已为社区贡献7条内容
所有评论(0)