window.onload = function() { var sp = document.getElementsByTagName("span")[0]; function fn() { var future = new Date(2019, 12, 12).getTime(); var now = new Date().getTime(); var gap = future - now; var gapDay = Math.floor(gap / 1000 / 60 / 60 / 24); var gapHour = Math.floor((gap / 1000 / 60 / 60) % 24); if (gapHour < 10) { gapHour = "0" + gapHour; } var gapMin = Math.floor((gap / 1000 / 60) % 60); if (gapMin < 10) { gapMin = "0" + gapMin; } var gapS = Math.floor((gap / 1000) % 60); if (gapS < 10) { gapS = "0" + gapS; } var gapHS = Math.floor(gap % 1000); if (gapHS < 100) { gapHS = "0" + gapHS; } else if (gapHS < 10) { gapHS = "00" + gapHS; } sp.innerHTML = gapDay + "天" + gapHour + "时" + gapMin + "分" + gapS + "秒" + gapHS + "毫秒"; } fn(); setInterval(function() { fn(); }, 50); };
|