2024-03-28 10:42:52 +03:00
|
|
|
// Format time in "Jan 02, 2006" format
|
2024-03-27 11:51:33 +03:00
|
|
|
function formatDate(date) {
|
|
|
|
let dateFormat = new Intl.DateTimeFormat('en', {
|
|
|
|
year: 'numeric',
|
|
|
|
month: 'short',
|
|
|
|
day: 'numeric'
|
|
|
|
})
|
|
|
|
return dateFormat.format(Date.parse(date))
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:01:09 +03:00
|
|
|
// Set today's date
|
|
|
|
function updateDate() {
|
|
|
|
let todayDate = new Date()
|
|
|
|
let timeField = document.getElementById("today-date")
|
2024-03-27 11:51:33 +03:00
|
|
|
timeField.innerText = formatDate(todayDate.toISOString().split('T')[0])
|
2024-03-18 15:01:09 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-28 10:42:52 +03:00
|
|
|
// Start interval to update today's date every hour at 00:00
|
2024-03-18 15:01:09 +03:00
|
|
|
function callEveryHour() {
|
|
|
|
setInterval(updateDate, 1000 * 60 * 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Begin above interval
|
|
|
|
function beginDateUpdater() {
|
|
|
|
let nextDate = new Date();
|
|
|
|
nextDate.setHours(nextDate.getHours() + 1);
|
|
|
|
nextDate.setMinutes(0);
|
|
|
|
nextDate.setSeconds(0);
|
|
|
|
|
|
|
|
const difference = nextDate - new Date();
|
|
|
|
setTimeout(callEveryHour, difference);
|
|
|
|
}
|