0%
网站运行时间计算一
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
function showDatetime() { window.setTimeout("showDatetime()", 1000); let BirthDay = new Date("08/01/2019 00:00:00"); let today = new Date(); let timeold = (today.getTime() - BirthDay.getTime()); let sectimeold = timeold / 1000; secondsold = Math.floor(sectimeold); let msPerDay = 24 * 60 * 60 * 1000; let e_daysold = timeold / msPerDay; let daysold = Math.floor(e_daysold); let e_hrsold = (e_daysold - daysold) * 24; let hrsold = setZero(Math.floor(e_hrsold)); let e_minsold = (e_hrsold - hrsold) * 60; let minsold = setZero(Math.floor((e_hrsold - hrsold) * 60)); let seconds = setZero(Math.floor((e_minsold - minsold) * 60)); document.querySelector('#old-now').innerHTML = " 已运行 " + daysold + " 天 " + hrsold + " 小时 " + minsold + " 分 <strong style='color:#A52A2A'>" + seconds + "</strong> 秒"; }
function setZero(i) { if (i < 10) { i = "0" + i; } return i; }
|
网站运行时间计算二
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| function createTime() { var now = new Date(); var run = new Date("05/28/2018 20:01:01"); var runTime = (now - run) / 1000, days = Math.floor(runTime / 60 / 60 / 24), hours = Math.floor(runTime / 60 / 60 - (24 * days)), minutes = Math.floor(runTime / 60 - (24 * 60 * days) - (60 * hours)), seconds = Math.floor((now - run) / 1000 - (24 * 60 * 60 * days) - (60 * 60 * hours) - (60 * minutes)); if (String(hours).length === 1) { hours = "0" + hours; } if (String(minutes).length === 1) { minutes = "0" + minutes; } if (String(seconds).length === 1) { seconds = "0" + seconds; }
document.querySelector(".run-times").innerHTML = "RunTime: " + days + "," + hours + ":" + minutes + ":" + seconds + ""; }
if (!document.hidden) { var siteTime = setInterval("createTime()", 500); } else { clearInterval(siteTime); }
|