网站运行时间

样例一

示例


<span id="runtime_span"></span>
<script type="text/javascript">function show_runtime(){window.setTimeout("show_runtime()",1000);X=new 
Date("7/16/2018 5:22: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>

样例二


<span>
    本站已运行
</span>
<span id="span_dt_dt">
</span>
<script>
    /*建站时间*/
    function show_date_time() {
        window.setTimeout("show_date_time()", 1e3);
        var BirthDay = new Date("2018/03/01"),
        today = new Date,
        timeold = today.getTime() - BirthDay.getTime(),
        msPerDay = 864e5,
        e_daysold = timeold / msPerDay,
        daysold = Math.floor(e_daysold),
        e_hrsold = 24 * (e_daysold - daysold),
        hrsold = Math.floor(e_hrsold),
        e_minsold = 60 * (e_hrsold - hrsold),
        minsold = Math.floor(60 * (e_hrsold - hrsold)),
        seconds = Math.floor(60 * (e_minsold - minsold));
        span_dt_dt.innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
    }
    show_date_time();
</script>

样例三


function showtime(times) { //传入时间的参数
    var time_1 = new Date(times).getTime();
    var time_2 = new Date().getTime();
    var time_3;
    var time_distance;
    //计算时间差 
    if (time_1 > time_2) {
        time_distance = time_1 - time_2;
    } else {
        time_distance = time_2 - time_1;
    }
    if (time_distance > 0) {
        // 天时分秒换算 
        var int_day = Math.floor(time_distance / 86400000);
        time_distance -= int_day * 86400000;
        var int_hour = Math.floor(time_distance / 3600000);
        time_distance -= int_hour * 3600000;
        var int_minute = Math.floor(time_distance / 60000);
        time_distance -= int_minute * 60000;
        var int_second = Math.floor(time_distance / 1000);
        // 时分秒为单数时、前面加零 
        if (int_day < 10) {
            int_day = "0" + int_day;
        }
        if (int_hour < 10) {
            int_hour = "0" + int_hour;
        }
        if (int_minute < 10) {
            int_minute = "0" + int_minute;
        }
        if (int_second < 10) {
            int_second = "0" + int_second;
        }
        time_3 = int_day + "天 " + int_hour + "时 " + int_minute + "分 " + int_second + "秒";
        return time_3;
    }
}

最后修改:2019 年 09 月 23 日 06 : 41 AM
如果觉得我的文章对你有用,请随意赞赏

发表评论