...

View Full Version : timezone file



shschesschamp
09-11-2011, 04:49 PM
The webpage doesn't display the proper times when I load it up. The GMT variable deals with the Greenwich timezone, which that time is used with offset variables in order to get the right times from each respective time zone in the branch offices. So far it seems only houston and new york display the right times or close to it all the other ones are way off. Please help me find the right formulas thank you.

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<!--
New Perspectives on JavaScript, 2nd Edition
Tutorial 2
Case Problem 3

Jackson Electronics World Clock
Author: Andy Duren
Date:

Filename: world.htm
Supporting files: je.css, logo.mpg, map.jpg, zones.js
-->

<title>Jackson Electronics World Clock</title>
<link href="je.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="zones.js"></script>
<script type = "text/javascript">
function worldClock() {
var today = new Date();
var offSet = today.getTimezoneOffset() * 60 * 1000;
var GMT = addTime(today, offSet);
var houstonoff = -360 * (60 * 1000);
var time1 = addTime(GMT, houstonoff); //houston office time
var washoff = -480 * (60 * 1000);
var time2 = addTime(GMT, washoff); //washington office time
var nyoff = -300 * (60 * 1000);
var time3 = addTime(GMT, nyoff); //new york office time
var englandoff = 0 * (60 * 1000);
var time4 = addTime(GMT, englandoff); //london office time
var japanoff = 540 * (60 * 1000);
var time5 = addTime(GMT, japanoff); //tokyo office time
var aussieoff = 660 * (60 * 1000);
var time6 = addTime(GMT, aussieoff); //sydney office time

document.zones.place1.value = showTime(time1);
document.zones.place2.value = showTime(time2);
document.zones.place3.value = showTime(time3);
document.zones.place4.value = showTime(time4);
document.zones.place5.value = showTime(time5);
document.zones.place6.value = showTime(time6);
}
</script>
</head>

<body onload="setInterval('worldClock()', 1000)">
<form id="zones" name="zones" action="">

<div id="headbar">
<img src="logo.jpg" alt="Jackson Electronics" />
<h2>Corporate Headquarters World Clock</h2>
</div>

<div id="timemap">

<input id="place1" name="place1" size="7" />
<input id="place2" name="place2" size="7" />
<input id="place3" name="place3" size="7" />
<input id="place4" name="place4" size="7" />
<input id="place5" name="place5" size="7" />
<input id="place6" name="place6" size="7" />

<img src="map.jpg" alt="World Map" id="map" />
<table>
<tr>
<th id="name1">Houston</th>
<th id="name2">London</th>
<th id="name3">New York</th>
<th id="name4">Seattle</th>
<th id="name5">Sydney</th>
<th id="name6">Tokyo</th>
</tr>
</table>
<table>
<tr>
<td id="address3">
<p><b>Jackson Electronics USA</b><br />
10010 Park Street<br />
New York, NY 10001<br />
<b>Phone: </b>(212) 555-1209<br />
<b>Fax: </b>(212) 555-4001
</p>
</td>
<td id="address4">
<p><b>Jackson Electronics Ltd.</b><br />
2349 Mitchell Street<br />
Seattle, WA 65091<br />
<b>Phone: </b>(381) 555-5499<br />
<b>Fax: </b>(381) 555-3181
</p>
</td>
<td id="address1">
<p><b>Jackson Electronics Latin America</b><br />
5150 Shasta Lane<br />
Houston, TX 32821<br />
<b>Phone: </b>(817) 555-8190<br />
<b>Fax: </b>(817) 555-2881
</p>
</td>
</tr>
<tr>
<td id="address2">
<p><b>Jackson Electronics Europe</b><br />
18 Northland Avenue<br />
London, England WC2N 5EA<br />
<b>Phone: </b>(+44) 0 870 555 7081<br />
<b>Fax: </b>(+44) 0 870 555 1788
</p>
</td>
<td id="address5">
<p><b>Jackson Electronics Pacifica</b><br />
171-105 Thomas Street<br />
Sydney NSW 2000, Australia<br />
<b>Phone: </b>(+61) 2 5555 8993<br />
<b>Fax: </b>(+61) 2 5555 7171
</p>
</td>
<td id="address6">
<p><b>Jackson Electronics Asia</b><br />
1-2-99 Sumiyoshi<br />
Hakata-Ku<br />
Tokyo 140-8781 Japan<br />
<b>Phone: </b>(+81) 3 5551 7817<br />
<b>Fax: </b>(+81) 3 5551 2398
</p>
</td>
</tr>
</table>
</div>

</form>
</body>
</html>

shschesschamp
09-11-2011, 04:51 PM
Sorry here's the js file that goes with it

/*
New Perspectives on JavaScript, 2nd Edition
Tutorial 2
Case Problem 3

Author: Andy Duren
Date:

Function List:
addTime(oldtime, milliseconds)
Used to add a specified number of milliseconds to a date object named oldtime.
A new date object with the new time value is returned by the function.

showTime(time)
Displays a time value in the format:
hh:mm AM/PM
*/

function addTime(oldtime, milliseconds) {
var newtime = new Date();
var newValue = oldtime.getTime() + milliseconds;
newtime.setTime(newValue);
return newtime;
}

function showTime(time) {
thisSecond=time.getSeconds();
thisMinute=time.getMinutes();
thisHour=time.getHours();

//change thisHour from 24-hour time to 12-hour time by:
// 1) if thisHour <12 than set ampm to " a.m." otherwise set it to " p.m."
var ampm = (thisHour < 12) ? "AM" : "PM";

// 2) subtract 12 from the thisHour variable
thisHour = (thisHour > 12) ? thisHour - 12 : thisHour;

// 3) if thisHour equals 0, change it to 12
thisHour = (thisHour == 0) ? 12 : thisHour;

//add leading zeros to minutes and seconds less than 10
thisMinute = thisMinute < 10 ? "0"+thisMinute : thisMinute;
thisSecond = thisSecond < 10 ? "0"+thisSecond : thisSecond;

return thisHour + ":" +thisMinute + ampm;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum