@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user