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("clock").value = hours + ':' + pad(now.getMinutes(), 2, '0') + ':' + pad(now.getSeconds(), 2, '0') + ampm; } window.onload = function() { displayTime(); var timer = setInterval(displayTime, 1000); document.getElementById('btnStop').onclick = function() { var btn = document.getElementById('btnStop'); if (btn.value == "Stop clock") { clearInterval(timer); btn.value = "Start clock"; } else { displayTime(); btn.value = "Stop clock"; timer = setInterval(displayTime, 1000); }; }; };