
How can I display current time with AM or PM using javascript?

<html>
<head>
<title>Time in am and pm</title>
<script type="text/javascript">
var todayDate=new Date();
var hours=todayDate.getHours();
var minutes=todayDate.getMinutes();
var seconds=todayDate.getSeconds();
var format ="AM";
if(hours>11)
{format="PM";
}
if (hours > 12) { hours = hours - 12; }
if (hours == 0) { hours = 12; }
if (minutes < 10){
minutes = "0" + minutes;
}
document.write("Time : " + hours + " : " + minutes + " : " + seconds + " " +format);
</script>
</head>
</html>
Description:
In javascript whenever you write new Date() it shows the current date in standard format with current day,date,time and GMT.You can have your own format.
getHours() shows hours of specified date.
getMinutes() shows minutes of specified date.
getSeconds() shows seconds of specified date.
By using above example condition you can set time with AM and PM.

Forgoing is the code for javascript time format am pm. Can you please explain the current time am pm in JavaScript too?