2025-03-29 21:58:38 +08:00
|
|
|
|
//获取计算机的时间信息
|
|
|
|
|
function updateLocalTime() {
|
|
|
|
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
2025-04-05 22:17:52 +08:00
|
|
|
|
const now = new Date();
|
|
|
|
|
|
|
|
|
|
// 获取时间(24小时制)
|
|
|
|
|
const timeStr = now.toLocaleTimeString('zh-CN', {
|
|
|
|
|
timeZone: timezone,
|
|
|
|
|
hour12: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取日期
|
|
|
|
|
const dateStr = now.toLocaleDateString('zh-CN', {
|
|
|
|
|
timeZone: timezone,
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
weekday: 'long'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.getElementById('timeDisplay').innerText = timeStr;
|
|
|
|
|
document.getElementById('dateDisplay').innerText = dateStr;
|
2025-03-29 21:58:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 22:17:52 +08:00
|
|
|
|
setInterval(updateLocalTime, 1000);
|
2025-03-29 21:58:38 +08:00
|
|
|
|
window.onload = updateLocalTime;
|