<!DOCTYPE html>
<html>
<head>
	<title>电子时钟</title>
	<meta charset="UTF-8">
	<script type="text/javascript">
		function showTime() {
			var now = new Date();
			var year = now.getFullYear();
			var month = now.getMonth() + 1;
			var day = now.getDate();
			var week = now.getDay();
			var hours = now.getHours();
			var minutes = now.getMinutes();
			var seconds = now.getSeconds();
<pre><code>		var weekArr = [&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;];
		var weekStr = &quot;星期&quot; + weekArr[week];

		var timeStr = year + &quot;年&quot; + month + &quot;月&quot; + day + &quot;日 &quot; + weekStr + &quot; &quot; + hours + &quot;:&quot; + minutes + &quot;:&quot; + seconds;
		document.getElementById(&quot;time_div&quot;).innerHTML = timeStr;
	}
	setInterval(&quot;showTime()&quot;, 1000);
&lt;/script&gt;
</code></pre>
</head>
<body>
	<div id="time_div"></div>
</body>
</html>
写一个html文件要求如下:利用定时器实现一个电子时钟要求在页面中实时显示当前时间精确到年月日和星期几

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

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