如何在网站底部添加网站运行时间,自动计算精确到秒代码教程

腾轩网 腾轩网 1216 其它教程


教程介绍

分享一个怎么网站运行时间代码可以更好的记录网站运行多久精确到秒的方法教程。

效果截图

1-191221140131.png

网站底部文件插入下列代码

<span id="runtime_span"></span>
<script type="text/javascript">function show_runtime(){window.setTimeout("show_runtime()",1000);X=new 
Date("09/30/2020 15:10:00");
Y=new Date();T=(Y.getTime()-X.getTime());M=24*60*60*1000;
a=T/M;A=Math.floor(a);b=(a-A)*24;B=Math.floor(b);c=(b-B)*60;C=Math.floor((b-B)*60);D=Math.floor((c-C)*60);
runtime_span.innerHTML="本站已运行: "+A+"天"+B+"小时"+C+"分"+D+"秒"}show_runtime();</script>