You are here: Re: Working with Timezones and DST « PHP Programming Language « IT news, forums, messages
Re: Working with Timezones and DST

Posted by Andy Hassall on 05/27/07 13:58

On 27 May 2007 06:24:49 -0700, Daz <cutenfuzzy@gmail.com> wrote:

>I am creating a JavaScript project which will allow users to see what
>time it is in other countries. I am wondering if there's any way to
>have the server work this out, without having to update a database
>constantly with the times and dates that certain countries set their
>clocks back or forward.
>
>Can this be done, or do I need to connect to a time server? Ideally, I
>need a time server that will return a JavaScript object containing the
>information I need, but I don't think one exists.
>
>Please could someone suggest the steps I need to take to quickly
>obtain the correct time for any given country, which will take DST
>into account? Sadly, to my knowledge, the UK is the only country that
>has hard-coded rules for when the clocks are changed, where as it
>seems to be a political thing for all other countries.
>
>If I have to run a database with this information, then so be it, but
>it seems like a lot of manual work, and I'm not sure how often I'd
>need to update it.

Most operating systems have comprehensive timezone data available, which gets
taken into account via the TZ environment variable when formatting UNIX
timestamps (which are always based on UTC).

PHP 5.1 introduced improved timezone handling into the core of PHP itself,
see: http://uk2.php.net/manual/en/function.date-default-timezone-set.php (which
is preferred over setting environment variables, if available).

<?php
foreach (array('US/Eastern', 'US/Central', 'UTC', 'Europe/London',
'Europe/Paris') as $tz)
{
putenv("TZ=$tz"); // or use date_default_timezone_set
print date("r") . " (TZ=$tz)\n";
}
?>

$ php test.php
Sun, 27 May 2007 09:56:21 -0400 (TZ=US/Eastern)
Sun, 27 May 2007 08:56:21 -0500 (TZ=US/Central)
Sun, 27 May 2007 14:56:21 +0100 (TZ=Europe/London)
Sun, 27 May 2007 15:56:21 +0200 (TZ=Europe/Paris)
Sun, 27 May 2007 13:56:21 +0000 (TZ=UTC)

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

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

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