初级的计时器

时间:2021-07-17 20:32:18

<div>
<p id="p"></p>
<p id="w"></p>
</div>
=====================CSS=========================

#p {
padding-top:30px;
padding-left:30px;
color:white;
}
div {
width:250px;
height:300px;
background-color:blue;
margin:10px auto;
}
#w {
width:120px;
height:120px;
background-color:green;
display:inline-block;
margin:60px;
text-align:center;
line-height:120px;
color:pink;
font-size:50px;
}
==========================JS================================

setInterval(function() {
var date = new Date;
var p = document.getElementById("p");
var arr = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
var a = date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日' + arr[date.getDay()] + date.getHours() + '小时' + date.getMinutes() + '分钟' + date.getSeconds() + '秒' + date.getMilliseconds() + '毫秒';
p.innerHTML = a;
var w = document.getElementById("w");
var e = date.getDate();
w.innerHTML = e;
}, 1000)