xxxxxxxxxx
function displayTime() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
// Formatting hours, minutes, and seconds to have two digits
hours = (hours < 10 ? "0" : "") + hours;
minutes = (minutes < 10 ? "0" : "") + minutes;
seconds = (seconds < 10 ? "0" : "") + seconds;
// Creating a string with the current time
var currentTimeString = hours + ":" + minutes + ":" + seconds;
// Displaying the current time inside an element with the id "timeContainer"
document.getElementById("timeContainer").innerHTML = currentTimeString;
}
// Calling the displayTime function every second to update the time
setInterval(displayTime, 1000);