百度已收录

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

关于网站运行时间统计代码百度一大堆,博主这里也有一份,也不知道是什么时候找的了,用起来还可以,目前自己也在用,这里就把代码和大家分享一下吧

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();

<span id="span_dt_dt"></span>引入,放在合适位置即可