Hugo:博客运行时间

Posted by Nefelibata on Wed 2024-03-27 | | about 1 mins
Last Modified on Thu 2024-05-23

文章参考自 https://thirdshire.com/hugo-stack-renovation/

显示效果

image-20240327160600919

解决方案

 1<!-- Add blog running time -->
 2本博客已稳定运行
 3<span id="runningdays" class="running-days"></span>
 4<script>
 5let s1 = '2024-3-18'; //website start date
 6s1 = new Date(s1.replace(/-/g, "/"));
 7let s2 = new Date();
 8let timeDifference = s2.getTime() - s1.getTime();
 9
10let days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
11let hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
12let minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
13
14let result = days + "天" + hours + "小时" + minutes + "分钟";
15document.getElementById('runningdays').innerHTML = result;
16</script>
17<br>