-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.html
43 lines (43 loc) · 975 Bytes
/
clock.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>clock</title>
<style>
div{
margin: 50px auto;
text-align: center;
}
</style>
</head>
<body>
<div>
<h3>电子时钟</h3>
<p id="clock"></p>
<p id="weekDay"></p>
</div>
<script type="text/javascript">
function toTime(n){
if(n<10){
return '0'+n;
}
else{
return ''+n;
}
}
var attime
function clock(){
var time=new Date();
var attime=toTime(time.getHours())+":"+toTime(time.getMinutes())+":"+toTime(time.getSeconds());
var clockElement=document.getElementById("clock");
clockElement.innerHTML=attime;
}
setInterval("clock()",1000);
var date=new Date();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var num=date.getDay();
var weekDayElement=document.getElementById("weekDay");
weekDayElement.innerHTML=weekday[num];
</script>
</body>
</html>