Forum Moderators: open

Message Too Old, No Replies

Multi clock javascript

         

gettin there

3:44 pm on May 6, 2005 (gmt 0)

10+ Year Member



First off, thanks for any help with this.

I have a multi clock script written in js that works just fine in IE but not in FF nor Netscape. The code seems simple enough, but then again I am not an expert at js. That being said, does anyone see any issues here? So, anyway, here's the code:

<html>
<head>
<title>time test</title>
</head>
<body>

<table border="0" cellspacing="1" width="400">
<tr>
<td width="33%"><font face="Arial" size="2"><b>New York</b></font></td>
<td width="33%"><font face="Arial" size="2"><b>London</b></font></td>
<td width="34%"><font face="Arial" size="2"><b>Tokyo</b></font></td>
</tr>
<tr>
<td width="33%"><p><font face="Arial" size="2"><span id="tP1">tP1</span></font></p></td>
<td width="33%"><p><font face="Arial" size="2"><span id="tP2">tP2</span></font></p></td>
<td width="34%"><p><font face="Arial" size="2"><span id="tP3">tP3</span></font></p></td>
</tr>
</table>

<script language="JavaScript">
function tN(){
return new Date();
}
function lZ(x){
return (x>9)?x:'0'+x;
}
function fY2(x){
x=(x<500)?x+1900:x;
return String(x).substring(2,4);
}

function tS(offs){
x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds());
x.setTime(x.getTime()+offs);
return x;
}

function dS(){
return ((tN().getTime()>fD(0,3,1,1).getTime())&&(tN().getTime()<fD(0,9,1,-1).getTime()))?3600000:0;
}

function fD(d,m,h,p){
var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(tN().getUTCFullYear(),nm,1,h,0,0),dOff=0;
if(p<0){
x.setTime(x.getTime()-86400000);
}
if(x.getDay()!=d){
dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d);
if(p<0&&dOff>0){
week-=7;
}
if(p>0&&dOff<0){
week+=7;
}
x.setTime(x.getTime()+((dOff+week)*86400000));
}
return x;
}

function dT(){
// Clock #1
offs=dS()-18000000;
tP1.innerText=eval("mN[tS(offs).getMonth()]+' '+tS(offs).getDate()+' '+lZ(tS(offs).getHours())+':'+lZ(tS(offs).getMinutes())+':'+lZ(tS(offs).getSeconds())+''+aP(tS(offs).getHours())");

// Clock #2
offs=dS()+0;
tP2.innerText=eval("mN[tS(offs).getMonth()]+' '+tS(offs).getDate()+' '+lZ(tS(offs).getHours())+':'+lZ(tS(offs).getMinutes())+':'+lZ(tS(offs).getSeconds())+''+aP(tS(offs).getHours())");

// Clock #3
offs=+32400000;
tP3.innerText=eval("mN[tS(offs).getMonth()]+' '+tS(offs).getDate()+' '+lZ(tS(offs).getHours())+':'+lZ(tS(offs).getMinutes())+':'+lZ(tS(offs).getSeconds())+''+aP(tS(offs).getHours())");

setTimeout('dT()',1000);
}

function aP(x){ return (x>11)?'pm':'am'; }

var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var mN=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

if(!document.all){
window.onload=dT;
}else{
dT();
}
</script>

</body>
</html>

Bernard Marx

4:56 pm on May 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The innerText property is IE-only.
Using innerHTML instead should cover most browsers these days.

gettin there

5:36 pm on May 6, 2005 (gmt 0)

10+ Year Member



So right you are! Thanks for that quick fix!