PDA

View Full Version : Clocks script



dukesmj
02-13-2007, 04:57 PM
The code below currently displays in the browser the following
I MEF/ Barstow
MarForRes
II MEF/ Alb
GMT
Iraq/Kuwait
Afghanistan

URL displaying the dates and times in the browswer
https://www.logcom.usmc.mil/clock.asp

I'm simply trying to add 1 more place in front of I MEF/Barstow so I will have 7 places displaying the date and time instead of 6. Where and what in this code do I change? I'm trying to add MarForRes which is -10 from Zulu.

Here is the code:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</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('Zulu', 0, 0, 'black'),
new tzone('Iraq', +3, 1, 'black'),
new tzone('IIMEF', -5, 1, 'black'),
new tzone('MarForRes', -6, 1, 'black'),
new tzone('Afgan', +4.5, 0, 'black'),
new tzone('IMEF Barstow', -8, 1, '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>' ;


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="421" >
<tr align="center" class="dataHeadSub">
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="83" valign="top" nowrap><b><font size="1">
I MEF/ Barstow<br>
(U)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="55" valign="top" nowrap><b><font size="1">
MarForRes<br>
(S)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="67" valign="top" nowrap><font size="1"><b>
II MEF/ Alb</b></font><b><font size="1"><br>
(R)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="51" valign="top" nowrap>
<b><font size="1">
GMT<br>
(Z)
</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="63" valign="top" nowrap><font size="1"><b>
Iraq/Kuwait<br>
(C)</b> </font></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" 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="51" nowrap></td>
<td id="Clock4" valign="top" bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="63" nowrap></td>
<td id="Clock5" valign="top" bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" 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></td>
</tr>
</table>

thetestingsite
02-14-2007, 02:29 AM
First off, not sure if it is my connection or if the server is down, but the link you posted is broken (Cannot find server). Second, try the following code (The parts in red are what I've changed):



<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</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('Zulu', 0, 0, 'black'),
new tzone('Iraq', +3, 1, 'black'),
new tzone('IIMEF', -5, 1, 'black'),
new tzone('MarForRes', -6, 1, 'black'),
new tzone('Afgan', +4.5, 0, 'black'),
new tzone('IMEF Barstow', -8, 1, 'black'),
new tzone('MarForRes','-10',1,'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&#37;" 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="421" >
<tr align="center" class="dataHeadSub">
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="83" valign="top" nowrap><b><font size="1">
I MEF/ Barstow<br>
(U)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="55" valign="top" nowrap><b><font size="1">
MarForRes<br>
(S)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="67" valign="top" nowrap><font size="1"><b>
II MEF/ Alb</b></font><b><font size="1"><br>
(R)</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="51" valign="top" nowrap>
<b><font size="1">
GMT<br>
(Z)
</font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="63" valign="top" nowrap><font size="1"><b>
Iraq/Kuwait<br>
(C)</b> </font></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" valign="top" nowrap>
<b><font size="1">
Afghanistan<br>
(D*) </font></b></td>
<td bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" valign="top" nowrap>
<b><font size="1">
MarForRes<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="51" nowrap></td>
<td id="Clock4" valign="top" bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="63" nowrap></td>
<td id="Clock5" valign="top" bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" nowrap></td>
<td id="Clock6" valign="top" bgcolor="#D0C8AD" style="font-family: Tahoma; font-size: 8pt" width="69" 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>


Not tested, but going off the code it should work.

Hope this helps.

dukesmj
02-14-2007, 12:58 PM
Thank you Thank you Thank you!! I appreciate it very much!! :p