-
Notifications
You must be signed in to change notification settings - Fork 8
/
digital-clock.html
143 lines (128 loc) · 3.33 KB
/
digital-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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<title>Digital Clock</title>
<style>
@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Open Sans", sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #060a1f;
}
#Clock h2 {
position: relative;
display: block;
color: #fff;
text-align: center;
margin: 10px 0;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.4em;
font-size: 0.8em;
}
#Clock #time {
display: flex;
}
#Clock #time div {
position: relative;
margin: 0 5px;
-webkit-box-reflect: below 1px linear-gradient(transparent, #0004);
}
#Clock #time div span {
position: relative;
display: block;
width: 100px;
height: 80px;
background: #2196f3;
color: #fff;
font-weight: 300;
display: flex;
justify-content: center;
align-items: center;
font-size: 3em;
z-index: 10;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
#Clock #time div span:nth-child(2) {
height: 30px;
font-size: 0.7em;
letter-spacing: 0.2em;
font-weight: 500;
z-index: 9;
box-shadow: none;
background: #127fd6;
text-transform: uppercase;
}
#Clock #time div:nth-last-child(2) span {
background: #ff006a;
}
#Clock #time div:nth-last-child(2) span:nth-child(2) {
background: #ec0062;
}
#Clock #time div:nth-last-child(1) span {
position: absolute;
bottom: 0;
width: 60px;
height: 40px;
font-size: 1.5em;
background: #fff;
color: #000;
-webkit-box-reflect: below 1px linear-gradient(transparent, #0004);
}
</style>
</head>
<body>
<div id="Clock">
<h2>The time is now</h2>
<div id="time">
<div>
<span id="hour">00</span>
<span>Hours</span>
</div>
<div>
<span id="minutes">00</span>
<span>Minutes</span>
</div>
<div>
<span id="seconds">00</span>
<span>Seconds</span>
</div>
<div>
<span id="ampm">AM</span>
</div>
</div>
</div>
<script type="text/javascript">
function clock() {
var hours = document.getElementById("hour");
var minutes = document.getElementById("minutes");
var seconds = document.getElementById("seconds");
var ampm = document.getElementById("ampm");
var h = new Date().getHours();
var m = new Date().getMinutes();
var s = new Date().getSeconds();
var am = "AM";
if (h > 12) {
h = h - 12;
var am = "PM";
}
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
hours.innerHTML = h;
minutes.innerHTML = m;
seconds.innerHTML = s;
ampm.innerHTML = am;
}
var interval = setInterval(clock, 1000);
</script>
</body>
</html>