»
EnglishFrenchVietnamese

Print - Clock Type script - JavaScriptBank.com

Full version: jsB@nk » Time » Clock » Clock Type script
URL: https://www.javascriptbank.com/clock-type-script.html

Clock Type script © JavaScriptBank.comThis is a really neat little script that can display the current time in 'Military Time' or '12 Hour Time' with the push of a button. Give it a try, it's neat!

Full version: jsB@nk » Time » Clock » Clock Type script
URL: https://www.javascriptbank.com/clock-type-script.html



JavaScript
<SCRIPT><!-- Beginvar change=1function showMilitaryTime(){  if(change!=1){button.value="24h";return true}    else button.value="12h";return false;}function showTheHours(hour){  if(showMilitaryTime()||(hour>0&&hour<13)){    if(hour==0)hour=12;return(hour);}  if(hour==0){return(12);}return(hour-12);}function showZeroFilled(inValue){  if(inValue>9){return inValue;}return "0"+inValue;}function showAmPm(){  if(showMilitaryTime()){return("");}  if(now.getHours()<12){return(" AM");}return(" PM");}function showTheTime(){  now=new Date()  hour=showZeroFilled(showTheHours(now.getHours()))  min=showZeroFilled(now.getMinutes())  sec=showZeroFilled(now.getSeconds())  ampm=showAmPm()  //this var defines how the clock will appear in the text box  //it is setup like an equasion  clock.value=hour+":"+min+":"+sec+ampm  setTimeout("showTheTime()",100)}onload=showTheTime// End --></SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<INPUT id=clock style="BACKGROUND: #ffff33; WIDTH: 75px" size="20"><INPUT id=button onclick=change*=-1 style="BACKGROUND: #ffff33; WIDTH: 40px" type=button value=12h><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->