Showing Live time in Web Page using Javascript

Dheeraj Kumar Gunti

Reading Time : ( words)

function dTime() {
    var d = new Date();
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();
    //add a zero in front of numbers < 10
       m = checkTime(m);
       s = checkTime(s);
    var dd = "AM";
    var hh = h;
    if (hh >= 12) {
          hh = h - 12;
          dd = "PM";
    }
    if (hh == 0) {
          hh = 12;
    }
       document.getElementById('txt').innerHTML = d.toDateString() + "  " + hh + ":" + m + ":" + s + " " + dd;
       t = setTimeout('dTime()', 500);
}

function checkTime(i) { if (i < 10) { i = "0" + i; } return i; }