-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (37 loc) · 857 Bytes
/
script.js
File metadata and controls
46 lines (37 loc) · 857 Bytes
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
function showTime() {
let date = new Date();
let hours = date.getHours(); //0-23
let minutes = date.getMinutes(); //0-59
let seconds = date.getSeconds(); //0-59
let formatHours = convertFormat(hours)
hours = checkTime(hours)
hours = addZero(hours)
minutes = addZero(minutes)
seconds = addZero(seconds)
document.getElementById('clock').innerHTML = `${hours} : ${minutes} : ${seconds}
${formatHours}`
}
function convertFormat(time) {
let format = 'AM'
if (time >= 12) {
format = 'PM'
}
return format
}
function checkTime(time) {
if (time > 12) {
time = time - 12;
}
if (time === 0) {
time = 12;
}
return time
}
function addZero(time) {
if (time < 10) {
time = "0" + time;
}
return time
}
showTime()
setInterval(showTime, 1000)