博客网站运行时间 网站倒计时 运行天数代码

, Read in about 2 min

Posted by Ryen on Thursday, February 25, 2021
With final update in December 26,2023

本文总阅读量

由于每次美化时,翻译插件自动将代码给我转义了,导致代码失效,也懒得一个个去改回来,就留一个下次用吧。。。。。

一.

<span id="runtime_span"></span><script type="text/javascript">function show_runtime(){window.setTimeout("show_runtime()",1000);X=new Date("4/15/2019 09:17:21");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>

二.

<script>
function secondToDate(second) {
    if (!second) {
        return 0;
    }
    var time = new Array(0, 0, 0, 0, 0);
    if (second >= 365 * 24 * 3600) {
        time[0] = parseInt(second / (365 * 24 * 3600));
        second %= 365 * 24 * 3600;
    }
    if (second >= 24 * 3600) {
        time[1] = parseInt(second / (24 * 3600));
        second %= 24 * 3600;
    }
    if (second >= 3600) {
        time[2] = parseInt(second / 3600);
        second %= 3600;
    }
    if (second >= 60) {
        time[3] = parseInt(second / 60);
        second %= 60;
    }
    if (second > 0) {
        time[4] = second;
    }
    return time;
}
</script>
<script type="text/javascript" language="javascript">
function setTime() {
    // 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
    var create_time = Math.round(new Date(Date.UTC(2019, 4, 15, 0, 0, 0))
            .getTime() / 1000);
    // 当前时间秒数,增加时区的差异
    var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
    currentTime = secondToDate((timestamp - create_time));
    currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
            + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
            + '秒';
    document.getElementById("htmer_time").innerHTML = currentTimeHtml;
}
setInterval(setTime, 1000);
</script>
坚持 ·第<span id="htmer_time" style="color: black;"></span>

「真诚赞赏,手留余香」

Ryen's Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付