写一个年月日时分秒毫秒的html电脑桌面时钟
<!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><script type="text/javascript">
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 + "-" + month + "-" + day + " " + h + ":" + m + ":" + s + ":" + ms;
setTimeout(startTime, 1);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function checkMs(i) {
if (i < 10) {
i = "00" + i;
} else if (i < 100) {
i = "0" + i;
}
return i;
}
</script>
</code></pre>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/fnEP 著作权归作者所有。请勿转载和采集!