<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>显示当前时间</title>
<style>
.center {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-size: 24px;
}
</style>
</head>
<body>
<div class="center" id="time"></div>
<script>
function updateTime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeString = hours + ":" + minutes + ":" + seconds;
document.getElementById("time").innerHTML = timeString;
setTimeout(updateTime, 1000); // 每秒更新一次时间
}
updateTime(); // 初始化时间
</script>
</body>
</html>