Skip to content

Instantly share code, notes, and snippets.

@Davisonpro
Created July 24, 2023 21:13
Show Gist options
  • Save Davisonpro/296f881619cb4f8988d93e950f0291e8 to your computer and use it in GitHub Desktop.
Save Davisonpro/296f881619cb4f8988d93e950f0291e8 to your computer and use it in GitHub Desktop.
<script>
// Function to display current date and time
function displayDateTime() {
const datetimeDisplayElement = document.getElementById('datetime-display');
// Create a new Date object
const currentDateTime = new Date();
// Extract the date and time components
const date = currentDateTime.toDateString();
const time = currentDateTime.toLocaleTimeString();
// Display the date and time in the span element
datetimeDisplayElement.textContent = `Current Date: ${date} | Current Time: ${time}`;
}
// Call the displayDateTime function to update the display immediately
displayDateTime();
// Update the display every second using setInterval
setInterval(displayDateTime, 1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment