JavaScript Code
// Function to display the current date and time
function displayDateTime() {
const now = new Date();
// Format the date
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
};
const dateString = now.toLocaleDateString('en-US', options);
// Format the time
const timeString = now.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
// Update the HTML elements
document.getElementById('date').textContent = dateString;
document.getElementById('time').textContent = timeString;
}
// Call the function immediately
displayDateTime();
// Update the time every second
setInterval(displayDateTime, 1000);