Reply to Re: DST & getTimezoneOffset()

Your name:

Reply:


Posted by ZeldorBlat on 09/14/06 23:34

bobkolk@gmail.com wrote:
> 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?

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

>
> 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?

No -- because not everyone observes DST.

>
> 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?

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
automatically.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация