Im making a digital clock for my webpage. But every time i enter the page, it takes 1 second before the string with the current time appears. Is there any way to change that and make it faster so it is not that notisable for the user? Thank you
My js code:
const add_zero = (number) => {
return number < 10 ? `0${number}` : number;
}
const show_current_time = () => {
setInterval(() => {
const today = new Date();
const month = today.getMonth() + 1;
const year = today.getFullYear();
const date = today.getDate();
const hours = add_zero(today.getHours());
const minutes = add_zero(today.getMinutes());
const current_date = `${date}/${month}/${year} ${hours}:${minutes} |`;
document.getElementById("show_current_time").innerHTML = current_date;
}, 1000)
}
window.onload = show_current_time;