<!DOCTYPE html>
<html>
<head>
	<title>显示系统当前时间</title>
	<script>
		function showTime() {
			var date = new Date();
			var hours = date.getHours();
			var minutes = date.getMinutes();
			var seconds = date.getSeconds();
			var ampm = hours >= 12 ? 'PM' : 'AM'; //判断上午下午
			hours = hours % 12; //转换成12小时制
			hours = hours ? hours : 12; //如果是0点,转换成12点
			minutes = minutes < 10 ? '0' + minutes : minutes; //如果分钟数小于10,加上前导0
			seconds = seconds < 10 ? '0' + seconds : seconds; //如果秒数小于10,加上前导0
			var currentTime = hours + ':' + minutes + ':' + seconds + ' ' + ampm;
			document.getElementById('time').innerHTML = currentTime;
			setTimeout(showTime, 1000); //每隔1秒钟更新一次时间
		}
	</script>
</head>
<body onload="showTime()">
	<p>系统当前时间:<span id="time"></span></p>
</body>
</html>
html显示系统当前时间

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

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