Click to See Complete Forum and Search --> : Time Zone Script


ahendersonaz
10-04-2003, 07:06 PM
I am creating a website that uses a javascript to detect the current time on a users computer and generate a list of current talk radio streams to listen to.

I have based the time around where I live, Pacific time, but I will be receiving a national promotion. I am looking to use any kind of script or whatever else, (cookies?) to have a user click on their time zone (Hawaiian, Alaska, Pacific, Mountain, Central, Eastern) and have the list generated and presented to them with their local time.

Quickly, here's how I'm doing it now: you visit the site and a javascript detects the day, then the hour on your PC clock and takes you to the appropriate file, ie: saturday/14.shtml is 2:00pm on Saturday.

Any ideas would be appreciated.

gil davis
10-05-2003, 05:26 AM
Usex = new Date();
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60;
Then calculate your timezone offset and change your list accordingly.

Either that, or use GMT or UTC functions.

ahendersonaz
10-06-2003, 02:26 AM
Pardon my amateur status, but how exactly would I customize this script? I don't see anything about GMT.

Charles
10-06-2003, 05:24 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;

Date.prototype.toUTCOffset = function (offset) {return new Date(this.getTime() + this.getTimezoneOffset() * 60000 + offset * Date.ONE_HOUR)}

Date.prototype.toTimeString = function () {return [this.getHours() < 13 ? this.getHours() : this.getHours() - 12, this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes(), this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds()].join (':') + (this.getHours() < 13 ? ' AM' : ' PM')}

document.write('<p id="time">-4 GMT ', new Date().toUTCOffset(-4).toTimeString(), '</p>');

if (document.getElementById) setInterval("document.getElementById('time').firstChild.data = '-4 GMT ' + new Date().toUTCOffset(-4).toTimeString()", 0.2 * Date.ONE_SECOND);

// -->
</script>