看了许多博客都安排了这个,我去网上搜了一下,网上花里胡哨的都有,没有我想要的。
我只想要一行文本 </s>网站已稳定运行 xxx 天 xx 时 xx 分 xx 秒<e>
,不要添加</s>xx 年<e>
,动态显示,不要刷新更新。
所以我问问这里的大佬有没有代码。
这个一般是wp的插件,实现要结合代码和js。写起来其实挺简单的,可以让gpt给你写一个。
@“James”#p38919 有 Flarum 可用的吗
@“14569”#p38920 Flarum需要一个小插件实现的,或者写死一个创建时间,放到js里边就好了。
```<!-- 运行时间 –>
<div class=“github-badge-big”>
<span class=“badge-subject”><i class=“fa fa-clock-o”></i> Running Time</span><span class=“badge-value bg-apricots”><span id=“blog_running_days” class=“odometer odometer-auto-theme”>8</span>
天
<span id=“blog_running_hours” class=“odometer odometer-auto-theme”>2</span> 小时
<span id=“blog_running_mins” class=“odometer odometer-auto-theme”>22</span> 分钟
<span id=“blog_running_secs” class=“odometer odometer-auto-theme”>12</span>秒
</span>
</div>
<script no-pjax=“”>
var blog_running_days = document.getElementById(“blog_running_days”);
var blog_running_hours = document.getElementById(“blog_running_hours”);
var blog_running_mins = document.getElementById(“blog_running_mins”);
var blog_running_secs = document.getElementById(“blog_running_secs”);
function refresh_blog_running_time() {
var time = new Date() - new Date(2024, 5, 12, 0, 0, 0); /此处日期的月份改为自己真正月份的前一个月/
var d = parseInt(time / 24 / 60 / 60 / 1000);
var h = parseInt((time % (24 * 60 * 60 * 1000)) / 60 / 60 / 1000);
var m = parseInt((time % (60 * 60 * 1000)) / 60 / 1000);
var s = parseInt((time % (60 * 1000)) / 1000);
blog_running_days.innerHTML = d;
blog_running_hours.innerHTML = h;
blog_running_mins.innerHTML = m;
blog_running_secs.innerHTML = s;
}
refresh_blog_running_time();
if (typeof bottomTimeIntervalHasSet == “undefined”) {
var bottomTimeIntervalHasSet = true;
setInterval(function () {
refresh_blog_running_time();
}, 500);
}
</script>
随便找了在别人网站里面扒出来的
不过是在wp里面的好像
@“FLZC”#p38922 谢谢,整个代码用 </s>```<e>
括起来比较适合阅读,下面是gpt的回复。
```
<div id=“runtime”>网站已稳定运行 0 天 0 时 0 分 0 秒</div>
<script>
// 设置网站开始运行的时间 (格式:年, 月, 日, 时, 分, 秒)
var startTime = new Date(2023, 5, 21, 12, 0, 0); // 示例:2023年6月21日12点0分0秒
function updateRuntime() {
var currentTime = new Date();
var diff = currentTime - startTime;
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
var hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((diff % (1000 * 60)) / 1000);
document.getElementById("runtime").innerText =
"网站已稳定运行 " + days + " 天 " + hours + " 时 " + minutes + " 分 " + seconds + " 秒";
}
// 每秒更新一次运行时间
setInterval(updateRuntime, 1000);
updateRuntime(); // 初始调用,避免页面加载时的延迟
</script><i>
```
[[1],[1,10]]
@“James”#p38925 感谢老哥提醒 俺刚注册啥也不懂
@“James”#p38925 我刚刚调教了一下 GPT。
</s><i> </i><p>网站已稳定运行 <span id="runtime">0 天 0 时 0 分 0 秒</span></p> <script> const startDate = new Date(2024, 2, 5, 12, 0, 0); function updateRuntime() { const now = new Date(); const diff = now - startDate; const seconds = Math.floor(diff / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); const remainingHours = hours % 24; const remainingMinutes = minutes % 60; const remainingSeconds = seconds % 60; document.getElementById('runtime').textContent = `${days} 天 ${remainingHours} 时 ${remainingMinutes} 分 ${remainingSeconds} 秒`; } setInterval(updateRuntime, 1000); updateRuntime(); </script><i> </i><e>
还是 GPT 生成的简洁
@“FLZC”#p38928 欢迎,很有爱的mjj。:huaji21:
@“14569”#p38929 是的,但是这个老弟先回答的,所以我把最佳回答给这个老弟了。 gpt真的是好东西。
@“James”#p38931 OK
不挂都忘了,网站搞了两年了
@“14569”#p38929 这个是真简洁,生活已经离不开gpt
@“FLZC”#p38922 果然还是这个好用,帖子里另一个代码有问题,计算显示都不对,秒数居然是递减的。