getHours() 12-hour format

This Function will give the perfect time format in 1-12 hours

 

Javascript Function:

function getClockTime(id){

var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var ap = "AM";
if (hour > 11) { ap = "PM"; }
if (hour > 12) { hour = hour - 12; }
if (hour == 0) { hour = 12; }
if (hour < 10) { hour = "0" + hour; }
if (minute < 10) { minute = "0" + minute; }
if (second < 10) { second = "0" + second; }

//var timeString = hour + ‘:’ + minute + ‘:’ + second + ” ” + ap;
var timeString = hour + ‘:’ + minute + ” / ” + ap;
document.getElementById(id).innerHTML = timeString;
setTimeout(‘getClockTime(“‘+id+'”);’,’1000′);
return true;
}

 

jQuery Function:

$(document).ready(function() {
getClockTime('date_time');
});