用Javascript计算网站在线时间

通过 | 4月 28, 2021
<script language="javascript">
function tick() {
var years,days,hours, minutes, seconds;
var openday = new Date('2007/03/01 00:00');
var today = new Date();
var total = (today.getTime()-openday.getTime())/1000;
years=Math.floor(total/31536000);
total=total-years*31536000;
days=Math.floor(total/86400);
total=total-days*86400;
hours=Math.floor(total/3600);
total=total-hours*3600;
minutes=Math.floor(total/60);
total=total-minutes*60;
seconds=Math.floor(total);
timeString = "辛会计博客已安全运行:"+years+"年"+days+"天"+hours+"时"+minutes+"分"+seconds+"秒";
document.getElementById("Clock").innerHTML = timeString;
window.setTimeout("tick();", 1000);
}
window.onload = tick;
</script>
<span id="Clock" style="float:right;font-size:0.850em"></span>
<p>
</p>
</span>