Javascript Time Display am/pm from Computer (quick tweak) -


just need quick tweak if thats ok. got code web , add am/pm displayed @ end of clock/time. many thanks...

<script> function starttime() { var today=new date(); var h=today.gethours(); var m=today.getminutes(); var s=today.getseconds(); // add 0 in front of numbers<10 m=checktime(m); s=checktime(s); document.getelementbyid('txt').innerhtml=h+":"+m+":"+s; t=settimeout(function(){starttime()},500); }  function checktime(i) { if (i<10)   {   i="0" + i;   } return i; } </script> 

<div id="txt"></div> 

or, if want displayed in 12-hour format:

<script type="text/javascript"> function starttime() { var today=new date(); var h=today.gethours(); var m=today.getminutes(); var s=today.getseconds(); // add 0 in front of numbers<10 m=checktime(m); s=checktime(s); var hd=h; document.getelementbyid('txt').innerhtml=(hd=0?"12":hd>12?hd-12:hd)+":"+m+":"+s+" "+(h<12?"am":"pm"); t=settimeout(function(){starttime()},500); }  function checktime(i) { if (i<10)   {   i="0" + i;   } return i; } </script> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -