DST & getTimezoneOffset()

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm writing a backend web app for a company that only has locations in
the US.  Why can't I, at login, pull their getTimezoneOffset() using
javascript, cookie it, then when I need to show a local time compute
the difference in their value in the cookie vs. my server's value?

I've seen a million articles about factoring in DST, but when my server
(which is in PA) switches to DST won't the difference value remain the
same since everyone rolls into DST on the same date?

For example, in June the server offset is 4 and in California the
offset is 7.  But in December the server is at 5 and California it's 8.
 So it's always a difference of 3.  No?

Re: DST & getTimezoneOffset()

bobkolk@gmail.com wrote:
Quoted text here. Click to load it

You could do that, but it won't work in all cases (see below).

Quoted text here. Click to load it

No -- because not everyone observes DST.

Quoted text here. Click to load it

Your best bet is to figure out what timezone they're actually in then
use timestamps appropriately when parsing and displaying dates and
times.  Timestamps are in UTC which doesn't have DST.  The timezone
setting of the machine will determine how dates are parsed (via
strtotime()) and how they are displayed (with date()) and will take
care of DST for you automatically.

Here's what you really want to do:

Call date_default_timezone_set() with your home timezone in PA at the
top of all your pages.  This is optional since PHP will take it from
the server, but recommended nonetheless.

If you want the current date and time, get the timestamp from the
time() function.

Before calling date() to format a date for display, call
date_default_timezone_set() with the user's timezone.

This will take care of all the converting for you and accomdate DST

Re: DST & getTimezoneOffset()

I forgot to mention ... I'm running PHP 4.3.4, so I don't have access
to date_default_timezone_set().   :(

Quoted text here. Click to load it

Do I still use javascript to get the user's timezone?  If so, how does
that differ from my original idea?  I'm still using the difference
between my server's timezone and the user's timezone to figure out how
to adjust the time, no?

Sorry -- time/date stuff always sends my head spinning.

ZeldorBlat wrote:
Quoted text here. Click to load it

Site Timeline