无聊之作

65次阅读

共计 768 个字符,预计需要花费 2 分钟才能阅读完成。

话不多说,直接上代码

<html>

<head>
    <title> 倒计时 </title>
</head>

<body>
    <div id="time1"></div>
    <p>-----------------------</p>   
    <div id="time2"></div>
</body>

<script src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
<script type="text/javascript">
    window.onload = function () {endTime();
    }

    function endTime() {var myDate = new Date();

        var timestamp = Date.parse(myDate) / 1000;

        var date = myDate.getDate();
        var year = myDate.getFullYear();
        var month = myDate.getMonth() + 1;

        var endtime1 = year + '-' + month + '-' + date + '12:00:00';
        var endtime2 = year + '-' + month + '-' + date + '18:00:00';

        var time1 = Date.parse(new Date(endtime1)) / 1000;
        var time2 = Date.parse(new Date(endtime2)) / 1000;
        if(time1 > timestamp) {$('#time1').text(time1 - timestamp +'S');
        }

        if(time2 > timestamp) {$('#time2').text(time2 - timestamp +'S');
        }

        setTimeout("endTime()", 1000);
    }
</script>

</html>

正文完
 0