[javascript] How to show current time in JavaScript in the format HH:MM:SS?

_x000D_
_x000D_
function checkTime(i) {_x000D_
  if (i < 10) {_x000D_
    i = "0" + i;_x000D_
  }_x000D_
  return i;_x000D_
}_x000D_
_x000D_
function startTime() {_x000D_
  var today = new Date();_x000D_
  var h = today.getHours();_x000D_
  var m = today.getMinutes();_x000D_
  var s = today.getSeconds();_x000D_
  // add a zero in front of numbers<10_x000D_
  m = checkTime(m);_x000D_
  s = checkTime(s);_x000D_
  document.getElementById('time').innerHTML = h + ":" + m + ":" + s;_x000D_
  t = setTimeout(function() {_x000D_
    startTime()_x000D_
  }, 500);_x000D_
}_x000D_
startTime();
_x000D_
<div id="time"></div>
_x000D_
_x000D_
_x000D_

DEMO using javaScript only

Update

Updated Demo

(function () {
    function checkTime(i) {
        return (i < 10) ? "0" + i : i;
    }

    function startTime() {
        var today = new Date(),
            h = checkTime(today.getHours()),
            m = checkTime(today.getMinutes()),
            s = checkTime(today.getSeconds());
        document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
        t = setTimeout(function () {
            startTime()
        }, 500);
    }
    startTime();
})();