无聊之作

话不多说,直接上代码

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

    原文作者:技术小白宅
    原文地址: https://segmentfault.com/a/1190000019023200
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞