// ============================================ // 6x9 Time // ============================================ // Version "Aplha" (2007-10-02) // // http://richardwinskill.uk/code/6x9time.php // // Copyright 2007 Richard Winskill // ============================================ function run_stntime(){ stntime(, , , "SxNtime"); stntime(, , , "SxNtime1"); stntime(, , , "SxNtime2"); stntime(, , , "SxNtime3"); stntime(, , , "SxNtime4"); stntime(, , , "SxNtime5"); } function stntime(chthour, chtmin, chtsec, chtid){ //Only run if element exists if(document.getElementById(chtid)){ //Add 1 to the seconds chtsec=chtsec+1; //When seconds reach 60, reset seconds to 0 and increase minutes by 1 if(chtsec>99){chtsec=0; chtmin=chtmin+1;} //When minutes reach 60, reset minutes to 0 and increase hour by 1 if(chtmin>99){chtmin=0; chthour=chthour+1;} //If hour is 0, make hour 24 (easier maths) if(chthour==0){chthour=20;} //When hour passes 24, reset hour to 1; if(chthour>20){chthour=1;} //If hour is before noon or hour is midnight, it's AM; otherwise it's PM if(chthour<10 || chthour==20){ap=" am";} else {ap=" pm";} ap=""; //Remove this line when switching to 10-hour display //Create "outhour" variable to display a 10-hour time but keep the maths right by remembering 24-hour "chthour" variable outhour=chthour //(10-hour time disabled, showing full 20-hour format. To enable 10-hour, uncomment line below) //if(outhour>10){outhour=outhour-10;} //Add a leading zero to seconds a minutes and hourif they are less than 10 if(chtsec<10){secz="0";}else{secz="";} if(chtmin<10){minz="0";}else{minz="";} if(outhour<10){hourz="0";}else{hourz="";} //Output the time string to the HTML element with ID CHTID document.getElementById(chtid).innerHTML=hourz+outhour+":"+minz+chtmin+":"+secz+chtsec+ap; //Tell the function to repeat every 1000ms (1 second) setTimeout('stntime('+chthour+', '+chtmin+', '+chtsec+', "'+chtid+'")',); } } //Handle other window.onload's var prevonload=window.onload; if(typeof(prevonload)=="function"){window.onload=function(){prevonload();run_stntime()}; }else{ window.onload=function(){run_stntime()}; }