2019-11-28 倒计时

timer() {

var endTime =new Date(2019, 11, 1, 23, 59, 59)

var ts = endTime -new Date()

if (ts >0) {

var dd =parseInt(ts /1000 /60 /60 /24, 10)

var hh =parseInt(ts /1000 /60 /60 %24, 10)

var mm =parseInt(ts /1000 /60 %60, 10)

var ss =parseInt(ts /1000 %60, 10)

dd = dd <10 ? ('0' + dd) : dd// 天

    hh = hh <10 ? ('0' + hh) : hh// 时

    mm = mm <10 ? ('0' + mm) : mm// 分

    ss = ss <10 ? ('0' + ss) : ss// 秒

    document.getElementById('timer_d').innerHTML = dd

document.getElementById('timer_h').innerHTML = hh

document.getElementById('timer_m').innerHTML = mm

document.getElementById('timer_s').innerHTML = ss

setTimeout(function () {

this.timer()

}, 1000)

}

}

你可能感兴趣的:(2019-11-28 倒计时)