Display Clock

by Vetrivel Samidurai

HTML

<div id="time"></div>

JavaScript

(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()),
            months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
    days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var aa =  days[today.getDay()]+' '+months[today.getMonth()]+' '+today.getDate()+' '+today.getFullYear(),
 ampm = today.getHours() >= 12 ? 'pm' : 'am';
        document.getElementById('time').innerHTML = aa + "--" + h + ":" + m + ":" + s + " " + ampm;
        t = setTimeout(function () {
            startTime()
        }, 500);
    }
    startTime();
})();