FORK ME

console 命令行工具 X clear

                    
>
console
window.onload = function () {
    var countP = document.getElementById('countDown'),
        nowT = new Date(),
        tagT = new Date("2017,1,1"),
        leftTime = Math.ceil((tagT.getTime() - nowT.getTime())/(24 * 3600 * 1000)),
        timer;

    function checkNum (num) {
        if (num > 9) {
            return num;
        } else {
            return "0" + num;
        }
    }

    setInterval(function () {
        var timeP = document.getElementById('showTime'),
            date = new Date(),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate(),
            weekday = date.getDay(),
            hours = checkNum(date.getHours()),
            minutes = checkNum(date.getMinutes()),
            seconds = checkNum(date.getSeconds()),
            weekAry = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        timeP.innerHTML = "现在时间是" + year + "年" + month + "月" + day + "日," + weekAry[weekday] + hours + ":" + minutes + ":" + seconds;
    }, 500);
    timer = setInterval(function () {
        var countP = document.getElementById('countDown2'),
            nowT = new Date(),
            tagT = new Date("2016,11,11,11:11:11"),
            leftTime = Math.floor((tagT.getTime() - nowT.getTime())/1000),
            day = Math.floor(leftTime / (60 * 60 * 24)),
            hours = Math.floor(leftTime / (60 * 60) % 24),
            minutes = Math.floor(leftTime / 60 % 60),
            seconds = Math.floor(leftTime % 60);
        countP.innerHTML = "距离2016年11月11日11:11:11还有" + day + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
    }, 500);
    countP.innerHTML = "距离2017年还有" + leftTime + "天";
}
<body>
    <p id="showTime"></p>
    <p id="countDown"></p>
    <p id="countDown2"></p>
</body>