I found this script and it appears to work great in both Internet Explorer and Firefox.
I simple save the above in a .js file. Then, in your page, have the following code:Code:// Clock Script Generated By Maxx Blade's Clock v2.0d // http://www.maxxblade.co.uk/clock function timeSource(){ x=new Date(); x.setTime(x.getTime()); return x; } function leadingZero(x){ return (x>9)?x:'0'+x; } function twelveHour(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } function displayTime(){ document.getElementById('tP').innerHTML=eval(outputTime); setTimeout('displayTime()',1000); } function amPMsymbol(x){ return (x>11)?'pm':'am'; } function fixYear4(x){ return (x<500)?x+1900:x; } var dayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var monthNames=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var outputTime="dayNames[timeSource().getDay()]+', '+leadingZero(timeSource().getDate())+' '+monthNames[timeSource().getMonth()]+' '+fixYear4(timeSource().getYear())+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(timeSource().getSeconds())+amPMsymbol(timeSource().getHours())";
The original, generated script had an extra line that automatically loaded the script without the need of calling displayTime() in the <span></span> above. However, this generated JavaScript errors in IE7...so I eventually came up with the above solution.Code:<span id="tP"> <script language="javascript" type="text/javascript" src="clock.js"> //<![CDATA[ displayTime(); //]]> </script> </span>



LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks