forked from gdscgcu/Learn-with-Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
digital_clock.js
63 lines (55 loc) · 1.06 KB
/
digital_clock.js
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
<!DOCTYPE html>
<html>
<head>
<title> Digital Clock </title>
<style>
body{
background-color: black;
}
.Clock{
position: absolute;
color: green'
top: 50%;
left: 50%;
transform: translateX (-50%);
font-size: 60px;
font-family: Orbitron;
}
</style>
</head>
<body>
<div id = 'DigitalClock'> </div>
<script type = 'text/javascript'>
function showTime() {
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var session = 'AM';
if (h == 0){
h = 12; //12 hours format
}
if (h > 12){
h = h - 12; //12 hours format
session = 'PM';
}
/*
if (h < 10){ // 0 - 9
h = '0' + h ;
}
if (m < 10){ // 0 - 9
m = '0' + m ;
}
if (s < 10){ // 0 - 9
s = '0' + s ;
}
*/
h = (h < 10) ? '0' + h : h;
m = (m < 10) ? '0' + m : m;
s = (s < 10) ? '0' + s : s;
document.getElementById('DigitalClock').innerHTML = h + ':' + m + ':' + s + ' ' + session;
setTimeout(showTime, 1000);
}
</script>
</body>
</html>