2024-06-22 20:58:35 +02:00

27 lines
963 B
JavaScript

function updateClock() {
const now = new Date().toLocaleString("en-US", {timeZone: "Europe/Amsterdam"});
const cestTime = new Date(now);
let hours = cestTime.getHours();
let minutes = cestTime.getMinutes();
let seconds = cestTime.getSeconds();
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
const timeString = hours + ':' + minutes + ':' + seconds;
//12pm //am
const isDaytime = hours >= 0 && hours > 7;
const imageElement = document.getElementById('clock-icon');
imageElement.src = isDaytime ? '/assets/icons/sun_small.png' : 'assets/icons/moon_small.png';
document.getElementById('clock').textContent = timeString;
}
document.addEventListener("DOMContentLoaded", function(event) {
updateClock();
setInterval(updateClock, 1000);
});