Re: Adjusting for Timezone
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Adjusting for Timezone

From: Jim Davis <newsmonkey@vboston.com>
Date: Wed Aug 31 2005 - 05:55:14 CEST

Well, I took a nap and then was able to figure it out.

There are two general methods for doing this. I'll be used the term
"source" in relation to the given time and "target" in relation to the local
time zone (so the problem becomes "how to convert a source timezone to a
target timezone):

1) A two stage conversion. Step one uses the source timezone offset to
generate a UTC datetime. We then use the target offset to generate the
local time.

This works just fine... but it's rather inelegant in my opinion (needing the
middle-man irks me).

2) Do the basic math (never a personal strong point). Subtracting the
target from the source gives us our answer. For example:

Source offset is +1:00, target is -4:00: (+1 - -4) = 5
Source offset is -5:00, target is -5:00: (-5 - -5) = 0
Source offset is -7:00, target is 2:00: (-7 - +2) = -9

And so forth. The resulting number is the offset between the source date
and the target date: modify the target by the result and the conversion is
complete.

I hope this helps somebody else. ;^)

Jim Davis
Received on Tue Oct 18 03:14:57 2005