Skip to content

Instantly share code, notes, and snippets.

@Davisonpro
Created July 24, 2023 21:11
Show Gist options
  • Save Davisonpro/8405921e14ed045292277500b4e5178a to your computer and use it in GitHub Desktop.
Save Davisonpro/8405921e14ed045292277500b4e5178a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Display Current Date and Time</title>
</head>
<body>
<span id="datetime-display"></span>
<script>
// Function to display current date and time
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}`;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment