Javascript Date Objects 2

The Javascript routine used by this page formats the time in a 12-hour am/pm format:

It is now

 

The routine is stored externally in the file time2.js, and it is shown below:

var d=new Date();
ap="am";
h=d.getHours();
m=d.getMinutes();
s=d.getSeconds();
if (h>11) { ap = "pm"; }
if (h>12) { h = h-12; }
if (h==0) { h = 12; }
if (m<10) { m = "0" + m; }
if (s<10) { s = "0" + s; }
document.write(h + ":" + m + ":" + s + " " + ap);