Repository navigation
Expand file tree
/
Copy pathDigitalClock.html
More file actions
69 lines (65 loc) · 1.89 KB
/
Copy pathDigitalClock.html
File metadata and controls
69 lines (65 loc) · 1.89 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Digital Clock</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100dvh;
display: grid;
place-items: center;
}
#clock {
background-color: #b6b6b6;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
padding: 2rem;
}
#time {
background-color: rgb(39, 39, 39);
font-size: 100px;
color: aliceblue;
padding: 1rem;
border-radius: 10px;
}
#date {
font-size: 30px;
}
</style>
</head>
<body>
<div id="clock">
<h1 id="time"></h1>
<h3 id="date"></h3>
</div>
</body>
<script>
const time = document.getElementById("time");
const date = document.getElementById("date");
const clock = document.getElementById("clock");
setInterval(() => {
const dateObj = new Date();
const day = dateObj.toLocaleDateString(undefined, { weekday: "short" });
const month = dateObj.toLocaleDateString(undefined, { month: "short" });
const dayNum = dateObj.getDate().toString().padStart(2, "0");
const year = dateObj.getFullYear();
const hour = dateObj.getHours().toString().padStart(2, "0");
const minute = dateObj.getMinutes().toString().padStart(2, "0");
const second = dateObj.getSeconds().toString().padStart(2, "0");
date.innerHTML = `${day}, ${month} ${dayNum}, ${year}`;
time.innerHTML = `${hour}:${minute}:${second}`;
}, 1000);
</script>
</html>