-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.js
More file actions
29 lines (23 loc) · 722 Bytes
/
time.js
File metadata and controls
29 lines (23 loc) · 722 Bytes
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
document.addEventListener("DOMContentLoaded", () => {
const date = document.querySelector("#date");
const time = document.querySelector("#time");
updateTime(date, time);
setInterval(() => updateTime(date, time), 10000);
});
const updateTime = (date, time) => {
const now = new Date();
const dateFormatter = new Intl.DateTimeFormat("en-US", {
weekday: "long",
day: "numeric",
month: "long",
});
const timeFormatter = new Intl.DateTimeFormat("en-US", {
hour: "numeric",
minute: "numeric",
hour12: false,
});
const dateString = dateFormatter.format(now);
const timeString = timeFormatter.format(now);
date.textContent = dateString;
time.textContent = timeString;
};