html实时时间代码
<!DOCTYPE html>
<html>
<head>
<title>Real Time Clock</title>
<script>
function realTimeClock() {
var rtClock = new Date();
var hours = rtClock.getHours();
var minutes = rtClock.getMinutes();
var seconds = rtClock.getSeconds();
<pre><code> hours = (hours < 10 ? "0" : "") + hours;
minutes = (minutes < 10 ? "0" : "") + minutes;
seconds = (seconds < 10 ? "0" : "") + seconds;
var amPm = (hours < 12) ? "AM" : "PM";
hours = (hours > 12) ? hours - 12 : hours;
hours = (hours == 0) ? 12 : hours;
var currentTime = hours + ":" + minutes + ":" + seconds + " " + amPm;
document.getElementById("clock").innerHTML = currentTime;
setTimeout(realTimeClock, 1000);
}
</script>
<style>
#clock {
font-size: 48px;
text-align: center;
margin-top: 50px;
}
</style>
</code></pre>
</head>
<body onload="realTimeClock()">
<div id="clock"></div>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/Cwp 著作权归作者所有。请勿转载和采集!