-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (26 loc) · 1.03 KB
/
Copy pathscript.js
File metadata and controls
34 lines (26 loc) · 1.03 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
function updateClock() {
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
const formattedHours = String(hours).padStart(2, '0');
const formattedMinutes = String(minutes).padStart(2, '0');
const formattedSeconds = String(seconds).padStart(2, '0');
document.getElementById('hour').textContent = formattedHours;
document.getElementById('minute').textContent = formattedMinutes;
document.getElementById('second').textContent = formattedSeconds;
document.getElementById('ampm').textContent = ampm;
}
// date
function updateDate() {
const now = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const formattedDate = now.toLocaleDateString('pt-br', options);
document.getElementById('date').textContent = formattedDate;
}
setInterval(updateClock, 1000)
updateClock()
updateDate()