js倒计时

2016-09-06  本文已影响0人  TonyYu
// html 
<span class="time">
        距离抢购结束: <span class="red"><span class="t_d"><i>00</i>天</span>
                    <span class="t_h"><i>00</i>时</span>
                    <span class="t_m"><i>00</i>分</span>
                    <span class="t_s"><i>00</i>秒</span></span>
 </span>    
//倒计时
    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);
上一篇下一篇

猜你喜欢

热点阅读