<!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 &lt; 10 ? &quot;0&quot; : &quot;&quot;) + hours;
		minutes = (minutes &lt; 10 ? &quot;0&quot; : &quot;&quot;) + minutes;
		seconds = (seconds &lt; 10 ? &quot;0&quot; : &quot;&quot;) + seconds;

		var amPm = (hours &lt; 12) ? &quot;AM&quot; : &quot;PM&quot;;

		hours = (hours &gt; 12) ? hours - 12 : hours;

		hours = (hours == 0) ? 12 : hours;

		var currentTime = hours + &quot;:&quot; + minutes + &quot;:&quot; + seconds + &quot; &quot; + amPm;

		document.getElementById(&quot;clock&quot;).innerHTML = currentTime;

		setTimeout(realTimeClock, 1000);
	}
&lt;/script&gt;
&lt;style&gt;
	#clock {
		font-size: 48px;
		text-align: center;
		margin-top: 50px;
	}
&lt;/style&gt;
</code></pre>
</head>
<body onload="realTimeClock()">
	<div id="clock"></div>
</body>
</html>
html实时时间代码

原文地址: https://www.cveoy.top/t/topic/Cwp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录