forked from LiGhT-27/test1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (44 loc) · 901 Bytes
/
script.js
File metadata and controls
52 lines (44 loc) · 901 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
47
48
49
50
51
52
function showTime()
{
let date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds= date.getSeconds();
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-=12;
}
if(time === 0)
{
time=12;
}
return time;
}
function addZero(time)
{
if(time<10)
{
time='0'+time;
}
return time;
}
showTime();
setInterval(showTime,1000);