Countdown for limited-time offers

//Counting down
$(document).ready(function(){
var doing_enddate = "2018/04/16 18:00:00";//Counting down
var start_enddate = "2018/09/09 09:00:00"; //The countdown is about to start
run(doing_enddate,'doing_time');
run(start_enddate,'start_time');
run(doing_enddate,'doing_time_up');
run(start_enddate,'start_time_up');
});
function run(enddate,dateshowhtml ){//dateshowhtml where to display the countdown must be id
//If enddate is the Date type passed in in the background, it is directly converted to milliseconds
enddate=new Date(enddate).getTime();
//Execute at a speed of 500 milliseconds (It can avoid the situation where the slow execution of the method will affect the display effect) 0
var time = 500;
setInterval("dateDif('"+enddate+"','"+dateshowhtml+"')",time);
}
//Calculate time difference
function dateDif(enddate,dateshowhtml){
var date = enddate - new Date().getTime();
var days = date / 1000 / 60 / 60 / 24;
var daysRound = Math.floor(days) > 0 ? Math.floor(days) : '';
var hours = date/ 1000 / 60 / 60 - (24 * daysRound);
//hours = hours < 10 ? '0'+hours : hours;
var hoursRound = Math.floor(hours) < 10 ? '0'+Math.floor(hours) : Math.floor(hours);
var minutes = date / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
//minutes = minutes < 10 ? '0'+minutes : minutes;
var minutesRound = Math.floor(minutes) < 10 ? '0'+Math.floor(minutes) : Math.floor(minutes);
var seconds = date/ 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
//seconds = seconds < 10 ? '0'+seconds : seconds;
var secondsRound = Math.floor(seconds) < 10 ? '0'+Math.floor(seconds) : Math.floor(seconds);
if(daysRound>0){
var time = daysRound+'.'+hoursRound+':'+minutesRound+':'+secondsRound;
}else{
var time = hoursRound+':'+minutesRound+':'+secondsRound;
}
$('#'+dateshowhtml).text(time);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324521227&siteId=291194637