console
class Tick{
constructor(){
this.aSpan=document.querySelectorAll("span");
this.times=document.getElementById("times");
}
toDouble(n){
return (n<10)?('0'+n):(''+n);
}
getCurTime(){
var endtime = new Date(this.times.getAttribute('data-endtime')).getTime();
var nowtime = new Date().getTime();
var youtime = endtime - nowtime;
var seconds = youtime / 1000;
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var CHour = hours % 24;
var CMinute = minutes % 60;
var CSecond = Math.floor(seconds % 60);
if (endtime > nowtime) {
if (days>0){
return this.times.innerHTML=`<span>${days}</span><em>天</em><span>${CHour}</span><em>时</em><span>${CMinute}</span><em>分</em><span>${CSecond}</span><em>秒</em>`
}else{
return this.times.innerHTML=`<span>${CHour}</span>时<span>${CMinute}</span>分<span>${CSecond}</span>秒`
}
}
}
tick(){
setInterval(this.getCurTime.bind(this),1000)
}
}
oTick=new Tick();
oTick.getCurTime();
oTick.tick();
<div id="times" data-endtime="4/6/2019 11:45:00"></div>