Demo

<html> <body onload="startTime()"> <h2>Time is:</h2> <div id="txt"></div> <script> function startTime() { const now= new Date(); let h = now.getHours(); let m = now.getMinutes(); let s = now.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('txt').innerHTML = h + ":" + m + ":" + s; setTimeout(startTime, 1000); } function checkTime(i) { if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 return i; } </script> </body> </html>