hexo+next设置网站运行时间


效果预览:

image-20200719000704508

1.找到hexo\themes\next\layout\_partials\footer.swig添加如下代码:

<!--添加网站运行时间 -->
{%- if (theme.running_time && theme.running_time.enable && theme.running_time.create_time){ %}
    <span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
    <script>
    function createtime() {
        var now = new Date();
        function createtime() {
        var grt= new Date({%- theme.running_time.create_time %});//此处修改你的建站时间或者网站上线时间
        now.setTime(now.getTime()+250);
        days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
        hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
        if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
        mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
        seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
        snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
        document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
    }
setInterval("createtime()",250);

    </script>
{%- } %}
<!-- 添加网站运行时间 -->

2.修改主题配置文件_config.yml添加如下代码

# 网站运行时间,格式形如:“本站已安全运行 12 天 11 小时 16 分 31 秒”
# Runing Time
running_time:
 enable: true
 create_time: '07/05/2020 17:38:00' #此处修改你的建站时间或者网站上线时间

完毕!


版权属于:Heson

本文链接:https://www.heson10.com/posts/46662.html


—— 评论区 ——