You are here: Re: How-to: time-zone conversion by name? « All PHP « IT news, forums, messages
Re: How-to: time-zone conversion by name?

Posted by Dennis de Wit on 08/09/06 08:07

Shai Halevi wrote:
> I'm trying to write a general-purpose PHP code for the following task:
>
> Step 1: The user specifies some date in the future (call it "the
> deadline"), which I parse via strtotime. This date is stored in the
> database.
>
> Step 2: Every time the user returns to the site, it sees a message
> saying, "deadline is XXX, time now is YYY". (Or maybe "deadline is XXX,
> time left is YYY").
>
> So far no problem. But I also want the user to specify in Step 1 in
> what time-zone these XXX and YYY should be displayed. For example, the
> user can ask to specify the dates in America/New_York time, or in UTC,
> or in the server's local time, or whatever.
>
> Moreover, this is to be a "general-purpose code", I don't know the
> local time-zone of the server, nor can I make any assumptions ahead of
> time about whether or not daylight saving time it observed in either
> the server's time-zone or the target time-zone. (And if it is observed
> in both, I don't know if the switch occurs at the same time in both.)
> Finally, this should work with PHP 4.x (so no date_default_timezone_set
> for me), and I cannot rely on the timezone environment variable being
> available either.
>
> One possible way to solve this is to compute the offset between the
> target time and the server time (or between the target time and UTC) at
> the deadline. Can anyone explain to me how to do that under the
> constraints from above?
>
> Thanks,
>
> -- Shai Halevi
>


First thing that came up in my mind is: calculate the time difference
between your time and the time on the server. That would give you
information on where the server is placed and what time it uses. You can
ask the user to enter his timezone information and extract/add this to
the time he enters so the time noted in the database is server-local-time.

But.... I'm not really sure how you can tell wether a certain region is
in daylight savings time. I know that my country (the netherlands) has
different dates for daylight savings time compared to for example The
United States. Also, I'm not really sure why you would take the daylight
savings times into account.

I hope this helps you out a bit.

Dennis

 

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

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