Source code function pad(str, cols, ch) { while ((""+str).length < cols) str = ch + str; return str; } function displayTime() { var militaryformat = false; if (document.getElementById("miltime").checked) { militaryformat = true; } var now = new Date(); var hours = now.getHours(); var ampm = ""; if (!militaryformat) { if (hours >= 12) ampm = " pm"; else ampm = " am"; if (hours == 0) hours = 12; else if (hours > 12) hours -= 12; } document.getElementById("display").value = hours + ':' + pad(now.getMinutes(), 2, '0') + ':' + pad(now.getSeconds(), 2, '0') + ampm; setTimeout(displayTime,1000); } window.onload = displayTime;