26 lines
718 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//获取计算机的时间信息
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;
}
setInterval(updateLocalTime, 1000);
window.onload = updateLocalTime;