<div id="output"></div> <script> var time = function() { var date = new Date(); var sec = date.getSeconds(); output.innerHTML = (sec < 10) ? '0' + sec : sec; } var timer = setInterval(time, 1000); </script>