<span id="time"></span>var time = document.getElementById("time")
function countDownTime() {
var timer = setTimeout(function() {
var time1 = new Date().getTime();
//这里的time2只是当时写demo的时候举例
var time2 = "1504324800000";
var h, m, s;
var time3 = (time2 - time1) / 1000;
if (time3 > 0) {
if (time3 / 3600 < 10) {
h = "0" + Math.floor(time3 / 3600);
} else {
h = Math.floor(time3 / 3600);
}
if (time3 % 3600 / 60 < 10) {
m = "0" + Math.floor(time3 % 3600 / 60)
} else {
m = Math.floor(time3 % 3600 / 60)
}
if (time3 % 3600 % 60 < 10) {
s = "0" + Math.floor(time3 % 3600 % 60)
} else {
s = Math.floor(time3 % 3600 % 60)
}
time.innerHTML = h + ":" + m + ":" + s;
countDownTime()
} else {
clearTimeout(timer);
time.innerHTML = "00:00:00";
}
}, 1000)
}
countDownTime()
这只是24小时的倒计时,你可以参考下。