<!DOCTYPE html>
<html>
<head>
	<title>电脑桌面时钟</title>
	<style type="text/css">
		body {
			background-color: black;
			color: white;
			font-size: 50px;
			text-align: center;
			margin-top: 200px;
		}
	</style>
</head>
<body onload="startTime()">
<pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
	function startTime() {
		var today = new Date();
		var year = today.getFullYear();
		var month = today.getMonth() + 1;
		var day = today.getDate();
		var h = today.getHours();
		var m = today.getMinutes();
		var s = today.getSeconds();
		var ms = today.getMilliseconds();

		m = checkTime(m);
		s = checkTime(s);
		ms = checkMs(ms);

		document.body.innerHTML = year + &quot;-&quot; + month + &quot;-&quot; + day + &quot; &quot; + h + &quot;:&quot; + m + &quot;:&quot; + s + &quot;:&quot; + ms;

		setTimeout(startTime, 1);
	}

	function checkTime(i) {
		if (i &lt; 10) {
			i = &quot;0&quot; + i;
		}
		return i;
	}

	function checkMs(i) {
		if (i &lt; 10) {
			i = &quot;00&quot; + i;
		} else if (i &lt; 100) {
			i = &quot;0&quot; + i;
		}
		return i;
	}
&lt;/script&gt;
</code></pre>
</body>
</html
写一个年月日时分秒毫秒的html电脑桌面时钟

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

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