You are here: Re: DST & getTimezoneOffset() « PHP Programming Language « IT news, forums, messages
Re: DST & getTimezoneOffset()

Posted by bobkolk on 09/15/06 13:02

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

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

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

 

Navigation:

[Reply to this 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

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