-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
93 lines (83 loc) · 3.16 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="scss/style.css">
<title>Digital Clock</title>
</head>
<body>
<div id="time">
<div class="circle" style="--clr: #29f1ff;">
<div class="dots hr_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="hh"></circle>
</svg>
<div id="hours">00</div>
</div>
<div class="circle" style="--clr: #2afe00;">
<div class="dots min_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="mm"></circle>
</svg>
<div id="minutes">00</div>
</div>
<div class="circle" style="--clr: #ff4d00;">
<div class="dots sec_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="ss"></circle>
</svg>
<div id="seconds">00</div>
</div>
<div class="ap">
<div id="am-pm">AM</div>
</div>
</div>
<script>
setInterval(() => {
let hours = document.getElementById('hours');
let minutes = document.getElementById('minutes');
let seconds = document.getElementById('seconds');
let ampm = document.getElementById('am-pm');
let hh = document.getElementById('hh');
let mm = document.getElementById('mm');
let ss = document.getElementById('ss');
let hr_dot = document.querySelector('.hr_dot');
let min_dot = document.querySelector('.min_dot');
let sec_dot = document.querySelector('.sec_dot');
let h = new Date().getHours();
let m = new Date().getMinutes();
let s = new Date().getSeconds();
let am = h >= 12 ? 'PM' : 'AM';
// converting 24hr to 12hr format
if (h>12) {
h = h-12;
}
// adding zero before single digit number
h = (h<10) ? '0' + h : h;
m = (m<10) ? '0' + m : m;
s = (s<10) ? '0' + s : s;
hours.innerHTML = h + "<br><span>Hours</span>";
minutes.innerHTML = m + "<br><span>Minutes</span>";
seconds.innerHTML = s + "<br><span>Seconds</span>";
ampm.innerHTML = am;
// 12 hrs clock
hh.style.strokeDashoffset = 440 - (440 * h) / 12;
// 60 minutes
mm.style.strokeDashoffset = 440 - (440 * m) / 60;
// 60 seconds
ss.style.strokeDashoffset = 440 - (440 * s) / 60;
// 360 / 12 = 30
hr_dot.style.transform = `rotate(${h * 30}deg)`;
// 360 / 60 = 6
min_dot.style.transform = `rotate(${m * 6}deg)`;
// 360 / 60 = 6
sec_dot.style.transform = `rotate(${s * 6}deg)`;
})
</script>
</body>
</html>