var inter;
intervatest("2019-08-22 09:12:00");
function intervatest(str) {
ShowCountDown(str, 'sjtest');
inter = window.setInterval(function () {
ShowCountDown(str, 'sjtest');
}, 1000);
}
clearInterval(inter);
function ShowCountDown(t, divname) {
var now = new Date();
var endDate = new Date(t);
var leftTime = endDate.getTime() - now.getTime();
var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10);//计算剩余的天数
var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数
var mm = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟数
var ss = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
dd = checkTime(dd);
hh = checkTime(hh);
mm = checkTime(mm);
ss = checkTime(ss);//小于10的话加0
var cc = document.getElementById(divname);
// cc.innerHTML = "距离" + year + "年" + month + "月" + day + "日还有:" + dd + "天" + hh + "小时" + mm + "分" + ss + "秒";
if (cc != null){
cc.innerHTML = dd + ":" + hh + ":" + mm + ":" + ss;
}
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}