Created
July 24, 2023 21:13
-
-
Save Davisonpro/296f881619cb4f8988d93e950f0291e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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