Web.QHMIT
.com
Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
Run
<!DOCTYPE html> <title>My Example</title> <time id="time"></time> <script> /* Create a JavaScript Date object for the current date and time, then extract the desired parts, then join them again in the desired format. */ var currentTime = new Date(), hours = currentTime.getHours(), minutes = currentTime.getMinutes(); // Add a leading zero if needed if (minutes < 10) { minutes = "0" + minutes; } // Join the parts time = hours + ":" + minutes; // Output the result to the above HTML element document.getElementById("time").innerHTML = time; </script>
Preview