This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.
Smartphone icons created by Freepik - Flaticon
Click the button to display the date.
<button onclick="displayDate()">The time is?</button> <script> function displayDate() { document.getElementById("demo").innerHTML = Date(); } </script>
Add zeros and colons to display the time:
function addZero(i) { if (i < 10) {i = "0" + i;} return i; } const d = new Date(); let h = addZero(d.getHours()); let m = addZero(d.getMinutes()); let s = addZero(d.getSeconds()); let time = h + ":" + m + ":" + s; document.getElementById("time").innerHTML = time;