26 lines
718 B
JavaScript
Raw Normal View History

2025-03-29 21:58:38 +08:00
//获取计算机的时间信息
function updateLocalTime() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
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
}
setInterval(updateLocalTime, 1000);
2025-03-29 21:58:38 +08:00
window.onload = updateLocalTime;