-
Notifications
You must be signed in to change notification settings - Fork 60
/
clockAuto.html
91 lines (78 loc) · 2.75 KB
/
clockAuto.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="page">
<div id="log_container">
</div>
<div id="top">
</div>
<div id="middle">
<div id="time_container">
<div id="apmOuterWrapper">
<div id="apmInnerWrapper">
<div id="apm"></div>
</div>
</div>
<div class="time" id="time"></div>
<div class="date" id="date"></div>
</div>
</div>
<div id="bottom">
</div>
</div>
<script>
// 深浅色模式标示
var lightMode = true
// 创建XMLHttpRequest对象
function createXHR() {
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr;
}
// 时钟模块
function clock() {
var date = new Date()
var utc8DiffMinutes = date.getTimezoneOffset() + 480
date.setMinutes(date.getMinutes() + utc8DiffMinutes)
var hour = date.getHours()
// 20点后6点前启用深色模式
if (hour > 19 || hour < 6) {
if (lightMode) {
document.getElementsByClassName('page')[0].style.color = '#ffffff'
document.getElementsByClassName('page')[0].style.backgroundColor = '#000000'
lightMode = false
}
} else {
if (!lightMode) {
document.getElementsByClassName('page')[0].style.color = '#000000'
document.getElementsByClassName('page')[0].style.backgroundColor = '#ffffff'
lightMode = true
}
}
var apm = '上<br>午'
if (hour > 12) {
apm = '下<br>午'
hour -= 12
}
var timeString = hour + ':' + ('0' + date.getMinutes()).slice(-2)
var dateString = (date.getMonth() + 1) + '月' + date.getDate() + '日'
var weekList = ['日', '一', '二', '三', '四', '五', '六']
var weekString = '星期' + weekList[date.getDay()]
document.getElementById('apm').innerHTML = apm
document.getElementById("time").innerHTML = timeString
document.getElementById("date").innerHTML = dateString + " " + weekString
}
clock()
setInterval("clock()", 60 * 1000)
</script>
</body>
</html>