为网站加入运行时间统计

首先,引入js文件,打开全局js文件,将js放到尾部即可

function jztime() {
    window.setTimeout("show_date_time()", 1000);
    BirthDay = new Date("1/25/2018 00:00:00"); //此处为建站日期
    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);
    yxtime.innerHTML = "本站已稳定运行:" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
}
jztime();

然后在你想要显示的地方引入

<span id="yxtime"></span>

如果想给文字加入颜色,则使用css即可

<span id="yxtime" style="color:#52bfe0f2;"></span>

效果图见本站底部

吾爱博客|AYFRE.COM 版权所有,转载请标明出处
吾爱博客 » 为网站加入运行时间统计

发表评论

吾爱博客|AYFRE.COM