-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathDigital_Clock.html
79 lines (66 loc) · 2.03 KB
/
Digital_Clock.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
<!-- Ques.7: Create a digital clock using JavaScript which shows the current time. -->
<!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" />
<title>Harsh Digital Clock</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500&display=swap");
body {
background: black;
}
.clock {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
color: #17d4fe;
font-size: 75px;
font-family: Orbitron;
letter-spacing: 7px;
border: 5px solid #17d4fe;
border-radius: 6px;
padding: 10px;
}
#d1{
font-size: 55px;
font-family: Orbitron;
color: #17d4fe;
margin-top: 12%;
margin-left:38%
}
</style>
</head>
<body>
<p id="d1"></p>
<div id="MyClockDisplay" class="clock" onload="showTime()"></div>
<script>
function showTime() {
var date = new Date();
var h = date.getHours(); // 0 - 23
var m = date.getMinutes(); // 0 - 59
var s = date.getSeconds(); // 0 - 59
var session = "AM";
if (h == 0) {
h = 12;
}
if (h > 12) {
h = h - 12;
session = "PM";
}
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
var time = h + ":" + m + ":" + s + " " + session;
var d = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
document.getElementById("MyClockDisplay").innerText = time;
document.getElementById("MyClockDisplay").textContent = time;
document.getElementById("d1").innerHTML= d;
setTimeout(showTime, 1000);
}
showTime();
</script>
</body>
</html>