总览页增加北京时间实时显示。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-03 03:26:45 +08:00
parent e62e0579de
commit 6d750d0e3f
3 changed files with 91 additions and 14 deletions
+43
View File
@@ -331,9 +331,52 @@
}
}
function formatBeijingNow() {
try {
return new Intl.DateTimeFormat("zh-CN", {
timeZone: "Asia/Shanghai",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(new Date());
} catch (e) {
const d = new Date();
const utc = d.getTime() + d.getTimezoneOffset() * 60000;
const bj = new Date(utc + 8 * 3600000);
const p = function (n) {
return String(n).padStart(2, "0");
};
return (
bj.getFullYear() +
"/" +
p(bj.getMonth() + 1) +
"/" +
p(bj.getDate()) +
" " +
p(bj.getHours()) +
":" +
p(bj.getMinutes()) +
":" +
p(bj.getSeconds())
);
}
}
function tickBeijingClock() {
const el = document.getElementById("overview-bj-time");
if (!el) return;
el.textContent = formatBeijingNow();
}
function boot() {
const btn = document.getElementById("btn-refresh");
if (btn) btn.addEventListener("click", refresh);
tickBeijingClock();
setInterval(tickBeijingClock, 1000);
refresh();
setInterval(refresh, 10000);
}