写一个年月日时分秒毫秒转动的html电脑桌面时钟
<!DOCTYPE html>
<html>
<head>
<title>电脑桌面时钟</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
background-color: black;
}
.clock {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
color: white;
text-shadow: 0 0 10px white;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<div class="clock"></div>
<script type="text/javascript">
function updateTime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milliseconds = now.getMilliseconds();
<pre><code> hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
var timeString = hours + ":" + minutes + ":" + seconds + ":" + milliseconds;
document.querySelector(".clock").innerHTML = timeString;
setTimeout(updateTime, 10); //每10毫秒更新一次时间
}
updateTime();
</script>
</code></pre>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/fnE6 著作权归作者所有。请勿转载和采集!