console
$(function(){
var t = null;
function clock(){
var _date = new Date();
var _y = _date.getFullYear();
var _m = _date.getMonth()+1;
var _d = _date.getDate();
var _h = checkTime(_date.getHours());
var _ms = checkTime(_date.getMinutes());
var _s = checkTime(_date.getSeconds());
document.getElementById('date').innerHTML ='当前时间 : ' + _y + '-' + _m + "-" + _d + ' ' + _h +':' + _ms +':' + _s;
t = setTimeout(clock,1000);
}
clock();
})
function countdown(et){
var _start = new Date();
var _end = new Date(et);
var _countdown = ((_end.getTime()-_start.getTime())/1000);
var _d = parseInt(_countdown/(60*60*24));
var _h = parseInt(_countdown/(60*60)%24);
var _m = parseInt(_countdown/60%60);
var _s = parseInt(_countdown%60);
document.getElementById('countdown').innerHTML = '距离活动开始还有' + checkTime(_d) + '天' +checkTime(_h) +'小时'+checkTime(_m)+'分'+checkTime(_s) + '秒';
ts = setTimeout(function(){countdown('2020/7/18 24:00:00')},1000);
}
function checkTime(i){
return i<10 ? i= '0'+i : i;
}
window.onload = function(){
var ts = null;
countdown('2020/7/18 24:00:00');
}
<div id="date"></div>
<div id="countdown"></div>