计算当年还剩多少时间的倒计时程序

<!DOCTYPE html >
<html>
<head>
<title></title>
</head>
<body>
    <span></span>
    <script>
        function counter() {
            var date = new Date();
            var year = date.getFullYear();
            var date2 = new Date(year, 12, 31, 23, 59, 59);
            var time = (date2 - date) / 1000;
            var day = Math.floor(time / (24 * 60 * 60));
            var hour = Math.floor(time % (24 * 60 * 60) / (60 * 60));
            var minute = Math.floor(time % (24 * 60 * 60) % (60 * 60) / 60);
            var second = Math.floor(time % (24 * 60 * 60) % (60 * 60) % 60);
            var str = year + "年还剩" + day + "" + hour + "" + minute + ""
                    + second + "";
            document.getElementsByTagName("span")[0].innerHTML = str;
        }
        setInterval(counter(), 500);
    </script>
</body>
</html>

 

posted @ 2016-05-25 10:55  绯乐  阅读(733)  评论(0编辑  收藏  举报