<!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>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐