写一个html文件要求如下:利用定时器实现一个电子时钟要求在页面中实时显示当前时间精确到年月日和星期几
<!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 = ["日", "一", "二", "三", "四", "五", "六"];
var weekStr = "星期" + weekArr[week];
var timeStr = year + "年" + month + "月" + day + "日 " + weekStr + " " + hours + ":" + minutes + ":" + seconds;
document.getElementById("time_div").innerHTML = timeStr;
}
setInterval("showTime()", 1000);
</script>
</code></pre>
</head>
<body>
<div id="time_div"></div>
</body>
</html>
原文地址: http://www.cveoy.top/t/topic/b6jf 著作权归作者所有。请勿转载和采集!