SanCi

用js实现网站运行时间的统计
代码分享:其中BirthDay = new Date("10/15/2017 17:47:39"...
扫描右侧二维码阅读全文
29
2018/04

用js实现网站运行时间的统计

代码分享:
其中BirthDay = new Date("10/15/2017 17:47:39");是建站时间,根据自己建站的日期修改,

function show_date_time() {
    window.setTimeout("show_date_time()", 1000);
    BirthDay = new Date("10/15/2017 17:47:39");
    today = new Date();
    timeold = (today.getTime() - BirthDay.getTime());
    sectimeold = timeold / 1000;
    secondsold = Math.floor(sectimeold);
    msPerDay = 24 * 60 * 60 * 1000;
    e_daysold = timeold / msPerDay;
    daysold = Math.floor(e_daysold);
    e_hrsold = (e_daysold - daysold) * 24;
    hrsold = Math.floor(e_hrsold);
    e_minsold = (e_hrsold - hrsold) * 60;
    minsold = Math.floor((e_hrsold - hrsold) * 60);
    seconds = Math.floor((e_minsold - minsold) * 60);
    span_dt_dt.innerHTML = "此站已运行:" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
}
show_date_time();

使用方法:
将这段代码写在script标签中,然后用以下代码引入即可
<span id="span_dt_dt"></span>

显示效果:

此站已运行: 365天10小时31分20秒

另一个更简短的方式显示网站运行天数
把代码放在适当的位置,一般都放在底部,比如主题的footer.php文件里,
其中,octo 04,2018 为建站日期,格式是月-日-年,根据自己建站的日期修改

本站已安全运行了:<span class="smalltxt"><script><!--BirthDay=new Date("octo 04,2018");//修改成自己网站创建时间today=new Date();timeold=(today.getTime()-BirthDay.getTime());sectimeold=timeold/1000secondsold=Math.floor(sectimeold);msPerDay=24*60*60*1000e_daysold=timeold/msPerDaydaysold=Math.floor(e_daysold);document.write("<font color=red>"+daysold+"</font>天");//--></SCRIPT>

显示效果:

本站已安全运行了: 365天


随机一言(显示内容与本文关)
Last modification:April 29th, 2018 at 03:37 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment