-
Notifications
You must be signed in to change notification settings - Fork 0
/
search4code.js
31 lines (31 loc) · 1.1 KB
/
search4code.js
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
function updateTimeAndDate() {
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes().toString().padStart(2, '0');
let amPm = hours >= 12 ? 'PM' : 'AM';
if (hours > 12) {
hours -= 12;
} else if (hours === 0) {
hours = 12;
}
let timeStr = hours.toString().padStart(2, '0') + minutes;
if (timeStr.startsWith('0')) {
timeStr = ' ' + timeStr.slice(1);
}
let month = (now.getMonth() + 1).toString().padStart(2, '0');
let day = now.getDate().toString().padStart(2, '0');
const year = now.getFullYear().toString().slice(-2);
if (month.startsWith('0')) {
month = ' ' + month.slice(1);
}
if (day.startsWith('0')) {
day = ' ' + day.slice(1);
}
const displayStr = timeStr + amPm + month + day + year;
for (let i = 0; i < 12; i++) {
document.getElementById('char' + i + '1').textContent = displayStr[i];
document.getElementById('char' + i + '2').textContent = displayStr[i];
}
}
updateTimeAndDate();
setInterval(updateTimeAndDate, 60000);