一个倒计时的小Demo

<div id="tcltime"></div>

<script>
    var tclTime = document.getElementById("tcltime");
    setInterval(fn,1);

    function fn(){
        var tfutureTime = new Date("2017/11/20 00:00:00");
        var tnowTime = new Date();
        var tsumMS = tfutureTime.getTime() - tnowTime.getTime();
        var tday = parseInt(tsumMS/1000/60/60/24);
        var thour = parseInt(tsumMS/1000/60/60%24);
        var tminute = parseInt(tsumMS/1000/60%60);
        var tsecond = parseInt(tsumMS/1000%60);

        if(tday<10){
            tday = "0"+tday;
        }
        if(thour<10){
            tthour = "0"+thour;
        }
        if(tminute<10){
            tminute = "0"+tminute;
        }
        if(tsecond<10){
            tsecond = "0"+tsecond;
        }

        tcltime.innerHTML = "距离活动还有:"+tday+"天"+thour+"小时"+tminute+"分钟"+tsecond+"秒钟";
    }
</script>



本文转载:CSDN博客