hibiscus/public/date.js

23 lines
618 B
JavaScript
Raw Normal View History

2024-03-18 15:01:09 +03:00
// Set today's date
function updateDate() {
let todayDate = new Date()
let timeField = document.getElementById("today-date")
timeField.innerText = todayDate.toISOString().split('T')[0]
}
// Starts interval to update today's date every hour at 00: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);
}