js根据当前时间和结束时间做倒计时

//倒数

countDown: function(){
	const that = this;
	//设置截止时间
	let outTime = that.$Init.user.outTime;
	let endDate = new Date(outTime).getTime() + 48 * 3600 * 1000; 
	let timeID = setInterval(function(){
		//获取当前时间
		let date = new Date();  
		let startDate = date.getTime();  
		
		
		//时间差  
		let leftTime = endDate - startDate;   
		if (leftTime>=0) {  
		    that.remainD = Math.floor(leftTime/1000/60/60/24);  
		    that.remainH = Math.floor(leftTime/1000/60/60%24) + that.remainD * 24;  
		    that.remainM = Math.floor(leftTime/1000/60%60) < 10 ? '0' + Math.floor(leftTime/1000/60%60) : Math.floor(leftTime/1000/60%60);  
		    that.remainS = Math.floor(leftTime/1000%60) < 10 ? '0' + Math.floor(leftTime/1000%60) : Math.floor(leftTime/1000%60);                     
		}else{
			 clearInterval(timeID); 
		}
	},1000)
},

你可能感兴趣的:(js根据当前时间和结束时间做倒计时)