forked from Dshwn/Hacktober_fest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigital Clock
88 lines (72 loc) · 1.43 KB
/
Digital Clock
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
<!DOCTYPE html>
<html>
<head>
<title>digital clock</title>
<style>
html,body{
height: 90%;
}
body{
background-image: url("https://img.wallpapersafari.com/desktop/1680/1050/29/52/4FLHJf.png");
background-size: cover;
background-position:center;
background-repeat: no-repeat;
display: grid;
place-items:center;
}
.clock{
background: black;
height: 120px;
width: 500px;
line-height: 120px;
text-align: center;
padding: 0 5px;
box-shadow: 4px 4px 4px 4px;
}
.clock .display{
font-size: 60px;
color:#3498DB ;
letter-spacing: 5px;
font-family:sans-serif;
}
</style>
</head>
<body>
<div class="clock">
<div class="display"></div>
</div>
<script>
setInterval(function()
{
const clock = document.querySelector(".display");
let time = new Date();
let sec = time.getSeconds();
let min = time.getMinutes();
let hr = time.getHours();
let day ='AM';
if(hr>12)
{
day = 'PM';
hr = hr - 12;
}
if(hr == 0)
{
hr = 12;
}
if(sec < 10)
{
sec = '0' + sec;
}
if(min < 10)
{
min = '0' + min;
}
if(hr < 10)
{
hr = '0' + hr;
}
clock.textContent = hr + ':' + min + ':' + sec + " " + day;
})
</script>
</body>
</html>