<!DOCTYPE html>
<html>
<head>
	<title>电脑桌面时钟</title>
	<style>
		.clock {
			font-size: 3em;
			font-weight: bold;
			text-align: center;
			margin-top: 50px;
			transform-origin: center center;
			animation: rotate 1s linear infinite;
		}
<pre><code>	@keyframes rotate {
		from {
			transform: rotateZ(0deg);
		}
		to {
			transform: rotateZ(360deg);
		}
	}
&lt;/style&gt;
</code></pre>
</head>
<body>
	<div class="clock" id="clock"></div>
<pre><code>&lt;script&gt;
	function updateClock() {
		let now = new Date();
		let year = now.getFullYear();
		let month = now.getMonth() + 1;
		if (month &lt; 10) {
			month = &quot;0&quot; + month;
		}
		let day = now.getDate();
		if (day &lt; 10) {
			day = &quot;0&quot; + day;
		}
		let hours = now.getHours();
		if (hours &lt; 10) {
			hours = &quot;0&quot; + hours;
		}
		let minutes = now.getMinutes();
		if (minutes &lt; 10) {
			minutes = &quot;0&quot; + minutes;
		}
		let seconds = now.getSeconds();
		if (seconds &lt; 10) {
			seconds = &quot;0&quot; + seconds;
		}
		let milliseconds = now.getMilliseconds();
		if (milliseconds &lt; 10) {
			milliseconds = &quot;00&quot; + milliseconds;
		} else if (milliseconds &lt; 100) {
			milliseconds = &quot;0&quot; + milliseconds;
		}

		let clock = document.getElementById(&quot;clock&quot;);
		clock.innerHTML = year + &quot;-&quot; + month + &quot;-&quot; + day + &quot; &quot; + hours + &quot;:&quot; + minutes + &quot;:&quot; + seconds + &quot;.&quot; + milliseconds;
	}

	setInterval(updateClock, 1);
&lt;/script&gt;
</code></pre>
</body>
</html
写一个年月日时分秒毫秒html电脑桌面转动的时钟

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

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