function getDouble(n){
if(n > 9){
return n;
}else{
return "0" + n;
}
function diffTime(startTime, endTime) {
var dTime = endTime - startTime;
var day,hour,minute,second;
var interval = dTime / 1000;
second = getDouble(Math。floor(interval % 60));
minute = getDouble(Math。floor(interval / 60 % 60));
hour = getDouble(Math。floor(interval / 60 / 60 % 24));
day = getDouble(Math。floor(interval / 60 / 60 / 24));
if(dTime > 0) {
return{
day: day,
hour: hour,
minute: minute,
second: second
} else {
return clearInterval(timeId);
}
}
}
var endTime = new Date(“2020-11-11 0:0:0”);
var day = document。querySelectir(“#day”);
var hour = document。querySelectir(“#hour”);
var minute = document。querySelectir(“#minute“);
var second = document。querySelectir(“#second“);
function countDown(){
var startTime = new Date();
var diffTime = diffTime(startTime,endTime);
if = diffTime
day。innerHTML = diffTime。day;
hour。innerHTML = diffTime。hour;
minute。innerHTML = diffTime。minute;
second。innerHTML = diffTime。second;
}
countDown();
var timeId = setInterval(countDown, 1000);
<span id = "day">00</span>
<span id = "hour">00</span>
<span id = "minute">00</span>
<span id = "second">00</span>