Hexo,添加网站运行时间

添加网站运行时间

添加位置:如果有统计量(如不蒜子统计量),放在不蒜子后面
灵活配置(推荐):设置成可以直接在配置文件中进行开启和关闭的形式

1.修改/themes/yilia/_config.yml

添加内容如下:

1
2
3
4
5
# 网站运行时间,格式形如:“本站已运行 100 天 10 小时 10 分 10 秒”
# Runing Time
running_time:
enable: true
create_time: '03/29/2020 17:00:00' #网站上线时间

添加内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!--添加网站运行时间 -->
<% if (theme.running_time && theme.running_time.enable && theme.running_time.create_time){ %>
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date();

function createtime() {
// var create_time = '<%- theme.running_time.create_time %>';
var create_time = new Date("03/29/2020 17:00:00");// 网站上线时间
now.setTime(now.getTime() + 250);
days = (now - create_time) / 1000 / 60 / 60 / 24;
dnum = Math.floor(days);
hours = (now - create_time) / 1000 / 60 / 60 - (24 * dnum);
hnum = Math.floor(hours);
if (String(hnum).length == 1) {
hnum = "0" + hnum;
}
minutes = (now - create_time) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes);
if (String(mnum).length == 1) {
mnum = "0" + mnum;
}
seconds = (now - create_time) / 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>
<% } %>

3.效果如下图所示

网站运行时间图示

参考博客

http://yansheng836.coding.me/article/50902a4.html


Hexo,添加网站运行时间
https://lcf163.github.io/2020/03/31/Hexo,添加网站运行时间/
作者
乘风的小站
发布于
2020年3月31日
许可协议