<span id="datetime" ></span>
<script>
function getWeekDay(date) {
const days = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
return days[date.getDay()];
}
function updateDateTime() {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const datetime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${getWeekDay(now)}`;
document.getElementById('datetime').textContent = datetime;
}
// 页面加载完成后更新时间
window.onload = function() {
updateDateTime();
setInterval(updateDateTime, 1000); // 每秒更新一次时间
};
</script>