/    Sign up×
Community /Pin to ProfileBookmark

Clock Code Help Please and Thank You!

Experts,

Thanks in advance for any help. I work at a military installation hence the timezones listed below.

I need to add 2 more time clocks to what I have already but I can’t seem to make it work so I’ve listed my code below and the URL so you can see it. The two I need added are:

Kuwait GMT +3
(Within the table this needs to fall after Iraq and Before Afghan)
and

IIIMEF/Kor GMT +9
(Within the table this needs to be the very first one)

Here is the clock via web browser how it looks now:

[url]http://www.logcom.usmc.mil/clock.asp[/url]

Here is the code:

<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>I MEF/ Barstow</title>
<table border=”0″ id=”table2″ bgcolor=”#FFFFFF”>
<tr>
<td bgcolor=”#FFFFFF”><SCRIPT language=”JavaScript”>

var timerID ;

function tzone(tz, os, ds, cl){
this.ct = new Date(0) ; // datetime
this.tz = tz ; // code
this.os = os ; // GMT offset
this.ds = ds ; // has daylight savings
this.cl = cl ; // font color
}

function UpdateClocks(){
var ct = new Array(
new tzone(‘IIMEF Albany’, -5, 1, ‘black’),
new tzone(‘Zulu’, 0, 0, ‘black’),
new tzone(‘MarForRes’, -6, 1, ‘black’),
new tzone(‘IMEF Barstow’, -8, 1, ‘black’),
new tzone(‘Iraq Kuwait’, +3, 1, ‘black’),
new tzone(‘MarForPac’, -10, 1, ‘black’),
new tzone(‘Afgan’, +4.5, 0, ‘black’)
) ;

var dt = new Date(); // [GMT] time according to machine clock

for(n=0 ; n<ct.length ; n++)
{
if (ct[n].ds == 1 && IsDST(ct[n].tz) ) ct[n].os++ ;
}

gmdt = new Date() ;
for (n=0 ; n<ct.length ; n++)
ct[n].ct = new Date(gmdt.getTime() + ct[n].os * 3600 * 1000 ) ;

document.all.Clock0.innerHTML =
‘<font color=black>’ + ClockString(ct[5].ct) + ‘</font>’ ;
document.all.Clock1.innerHTML =
‘<font color=black>’ + ClockString(ct[3].ct) + ‘</font>’ ;
document.all.Clock2.innerHTML =
‘<font color=black>’ + ClockString(ct[2].ct) + ‘</font>’ ;
document.all.Clock3.innerHTML =
‘<font color=black>’ + ClockString(ct[0].ct) + ‘</font>’ ;
document.all.Clock4.innerHTML =
‘<font color=black>’ + ClockString(ct[1].ct) + ‘</font>’ ;
document.all.Clock5.innerHTML =
‘<font color=black>’ + ClockString(ct[4].ct) + ‘</font>’ ;
document.all.Clock6.innerHTML =
‘<font color=black>’ + ClockString(ct[6].ct) + ‘</font>’ ;

timerID = window.setTimeout(“UpdateClocks()”, 1001) ;
}

function IsDST(place)
{
if (place == ‘Iraq’)
return IsBahDST();
else
return IsOtherDST();

}

function IsOtherDST()
{

var now = new Date();
var curYear = now.getFullYear();
var dtBeg;
var dtEnd;

if ( curYear == 2006)
{
for(i=1; i<=7; i++)
{
dtBeg = new Date(curYear, 3, i);
if(dtBeg.getDay()==0)
{
break;
}

}

for(i=25; i<=34; i++)
{
dtEnd = new Date(curYear, 9, i);
if(dtEnd.getDay()==0)
{
break;
}
}

if(now > dtBeg && now < dtEnd)
{return true;}
else
{return false;}
}

else
{

for(i=1; i<=7; i++)
{
dtBeg = new Date(curYear, 2, i);
if(dtBeg.getDay()==0)
{break; }
}

for(i=1; i<=7; i++)
{
dtEnd = new Date(curYear,10, i);
if(dtEnd.getDay()==0)
{break;}
}

if(now > dtBeg && now < dtEnd)
{return true;}
else
{return false; }

}

}

function IsBahDST()
{

var now = new Date();
var curYear = now.getFullYear();
var dtBeg = new Date(curYear, 3, 1);
var dtEnd = new Date(curYear, 9, 1);

if(now > dtBeg && now < dtEnd)
{
return true;
}
else
{
return false;
}

}

function monthName(month){
var monthN;
if (month == 1)
monthN = “Jan”;
if (month == 2)
monthN = “Feb”;
if (month == 3)
monthN = “Mar”;
if (month == 4)
monthN = “Apr”;
if (month == 5)
monthN = “May”;
if (month == 6)
monthN = “Jun”;
if (month == 7)
monthN = “Jul”;
if (month == 8)
monthN = “Aug”;
if (month == 9)
monthN = “Sep”;
if (month == 10)
monthN = “Oct”;
if (month == 11)
monthN = “Nov”;
if (month == 12)
monthN = “Dec”;
return monthN;
}

function ClockString(dt){
var stemp, ampm ;
var dt_year = dt.getUTCFullYear() ;
var dt_month = dt.getUTCMonth() + 1 ;
var dt_day = dt.getUTCDate() ;
var dt_hour = dt.getUTCHours() ;
var dt_minute = dt.getUTCMinutes() ;
var dt_second = dt.getUTCSeconds() ;

dt_year = dt_year.toString() ;
if (dt_minute < 10)
dt_minute = ‘0’ + dt_minute ;
if (dt_second < 10)
dt_second = ‘0’ + dt_second ;
stemp = dt_day + ‘ ‘ + monthName(dt_month) + ‘ ‘ + dt_year.substr(2,2);
stemp = stemp + ‘ ‘ + dt_hour + “:” + dt_minute + “:” + dt_second;
return stemp ;
}

</SCRIPT>

<script language=’javascript’>
<!–
function MSOTlPn_ShowToolPane(toolPaneView)
{
if (document.forms[‘_ctl6′].MSOGallery_FilterVisible) document.forms[‘_ctl6′].MSOGallery_FilterVisible.value = ‘false’;
document.forms[‘_ctl6′].MSOTlPn_View.value = toolPaneView;
if (arguments.length > 1) document.forms[‘_
ctl6′].MSOTlPn_SelectedWpId.value = arguments[1];
else document.forms[‘_ctl6′].MSOTlPn_SelectedWpId.value = ”;
document.forms[‘_
ctl6′].submit();
}
//–>
</script>

<SCRIPT LANGUAGE=’JavaScript’ >
<!–
//–>
</SCRIPT>

<link href=”/_layouts/1033/styles/Menu.css” rel=”stylesheet”/><style type=”text/css”>
.ms-SrvMenuUI { behavior:url(“/_
layouts/1033/Menu.htc”); }
table.MsoNormalTable
{mso-style-parent:””;
font-size:10.0pt;
font-family:”Times New Roman”;
}
</style><script src=”/_layouts/1033/Menu.js” type=”text/JavaScript” language=”JavaScript”></script><script type=”text/JavaScript” language=”JavaScript”>
<!–
var L_Menu_BaseUrl=”http://www.marcent.usmc.smil.mil“;
var L_Menu_LCID=”1033″;
var L_Menu_SiteTheme=””;
//–>
</script>

<SCRIPT LANGUAGE=”JavaScript”>
<!–
function newImage(arg) {
var rslt = new Image();
rslt.src = arg;
return rslt;
}

function changeImages(a, b) {
a.src = b;
}

newImage(“/_layouts/images/icongo02.gif”);
newImage(“/_
layouts/images/icongo03.gif”);
// –>
</SCRIPT>

<SCRIPT language=’javascript’ src=’/_layouts/1033/ie55up.js’></SCRIPT>

<table class=”ms-main” cellpadding=”0″ cellspacing=”0″ border=”0″ height=”80%” id=”table3″>

<tr> <td class=”ms-titleareaframe”> <div class=”ms-titleareaframe”>
<table width=”100%” border=”0″ class=”ms-titleareaframe” cellpadding=”0″ cellspacing=”0″ id=”table4″> <tr> <td>
<table style=”PADDING-LEFT: 2px;PADDING-TOP: 0px” cellpadding=”0″ cellspacing=”0″ border=”0″ bgcolor=”#FFFFFF” id=”table5″> <tr>
<td nowrap bgcolor=”#FFFFFF”>
<blockquote>
<blockquote>
<div align=”center”>
<table cellpadding=”0″ cellspacing=”0″ height=80% width=”589″ id=”table6″>
<tr> <!–<td align=center ID=”onetidPageTitle” class=”ms-pagetitle”>
U.S. Marine Corps Forces Central Command &nbsp;–><!–Home–></td>
<td align=”right”>
<div align=”center”>
<table border=”1″ ID=”table7″ class=”homeContentContainer” bgcolor=”#D0C8AD” cellspacing=”1″ width=”507″ >
<tr align=”center” class=”dataHeadSub”>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”83″ valign=”top” nowrap>
<b><font size=”1″>
MarForPac<br>
(W)</font></b></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”55″ valign=”top” nowrap>
<b><font size=”1″>
IMEF/Bar<br>
(U)</font></b></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”67″ valign=”top” nowrap>
<font size=”1″><b>
MarForRes</b></font><b><font size=”1″><br>
(S)</font></b></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”50″ valign=”top” nowrap>
<b><font size=”1″>
IIMEF/Alb<br>
(R)
</font></b></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”69″ valign=”top” nowrap>
<font size=”1″><b>GMT<br>
(Z)</b> </font></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”62″ valign=”top” nowrap>
<b><font size=”1″>
Iraq<br>
(C) </font></b></td>
<td bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”87″ valign=”top” nowrap>
<b><font size=”1″>
Afghanistan<br>
(D*) </font></b></td>
</tr>
<tr align=”center” class=”dataHead”>
<td id=”Clock0″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”83″ nowrap></td>
<td id=”Clock1″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”55″ nowrap></td>
<td id=”Clock2″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”67″ nowrap></td>
<td id=”Clock3″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”50″ nowrap></td>
<td id=”Clock4″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”69″ nowrap></td>
<td id=”Clock5″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”62″ nowrap></td>
<td id=”Clock6″ valign=”top” bgcolor=”#D0C8AD” style=”font-family: Tahoma; font-size: 8pt” width=”87″ nowrap></td>
</tr>
</table></div></td>
</tr>
</table>

</div>

<script>
UpdateClocks();
</script>
</blockquote>
</blockquote>
</td> <td align=”right” valign=”top” bgcolor=”#FFFFFF”> &nbsp;</td> </tr> </table>
<table cellpadding=”0″ cellspacing=”0″ border=”0″ width=”100%” id=”table8″> <tr>
<td height=”2″><IMG SRC=”/_layouts/images/blank.gif” width=”1″ height=”1″ alt=””></td> </tr> <tr>
<td class=”ms-titlearealine” height=”1″><IMG SRC=”/_
layouts/images/blank.gif” width=”1″ height=”1″ alt=””></td> </tr> </table> </td> </tr> </table>
</div> </td> </tr>

</table> <SCRIPT LANGUAGE=’JavaScript’ >
<!–
//–>
</SCRIPT>

</form>

</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jamNov 27.2007 — hey i've just skimmed through your code and you have 7 clocks in the updateClock function but you only go up to 6 further down the page?

from looking at the link i dont understand whats going wrong?
Copy linkTweet thisAlerts:
@nshiellNov 27.2007 — ditto
Copy linkTweet thisAlerts:
@dukesmjauthorNov 28.2007 — Are you talking about further down in my code where is goes from 0 to 6 which would count 7? Code that is there now is working fine for the 7 clocks. My problem is when I try to add one everything goes crazy.

Thanks
×

Success!

Help @dukesmj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...