-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
46 lines (42 loc) · 989 Bytes
/
index.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
<!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>clock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>digital clock</h1>
<div class="clock">12:50:10 AM</div>
</div>
<script >
const clock = document.querySelector('.clock')
function runclock(){
var time=new Date();
var hrs =time.getHours();
var min=time.getMinutes();
var sec=time.getSeconds();
var txt="AM";
if(hrs>12){
hrs=hrs-12;
text="PM";
}
else if(hrs==0){
hrs=12;
txt="AM";
// }
}
hrs=hrs<10?'0'+hrs:hrs;
min=min<10?'0'+min:min;
sec=sec<10?'0'+sec:sec;
clock.innerHTML = `${hrs} : ${min} : ${sec} ${txt}`;
// console.log(`${hrs} : ${min} : ${sec}`);
}
runclock();
setInterval(runclock,1000);
</script>
</body>
</html>