js倒计时

// html 

        距离抢购结束: 00
                    00
                    00
                    00
     
//倒计时
    function getRTime() {
            var timestamp = Date.parse(new Date()) / 1000;
            var EndTimeTamp = 1474387200; //1472051797
            var t = EndTimeTamp - timestamp;
            var d = Math.floor(t / 60 / 60 / 24);
            var h = Math.floor(t / 60 / 60 % 24);
            var m = Math.floor(t / 60 % 60);
            var s = Math.floor(t % 60);
            // alert(t)
            if (t < 0) {
                    clearInterval(time1);
            }
            document.getElementById("t_d").innerHTML = d + "天";
            document.getElementById("t_h").innerHTML = h + "时";
            document.getElementById("t_m").innerHTML = m + "分";
            document.getElementById("t_s").innerHTML = s + "秒";
    }
    var time1 = setInterval(getRTime, 1000);

你可能感兴趣的:(js倒计时)