SOURCE

console 命令行工具 X clear

                    
>
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);//"%"是取余运算,可以理解为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) //setInterval的this指向window,用bind改变this指向  
   }  
}  
oTick=new Tick();  
oTick.getCurTime();  
oTick.tick(); 
<div id="times" data-endtime="4/6/2019 11:45:00"></div>