|
Posted by Wayne C. Morris on 06/14/07 18:39
In article <IPadnUBY4L0JVO3bnZ2dnUVZWhednZ2d@giganews.com>,
"David T. Ashley" <dta@e3ft.com> wrote:
> "Gordon Burditt" <gordon@hammy.burditt.org> wrote in message
> news:1371gmc1eq1qp5f@corp.supernews.com...
> >>In a web database (PHP), per user, I'd like to allow each user to
> >>specify their timezone (this would change how times are adjusted for
> >>display for that user).
> >>
> >>How do I enumerate all possible timezones from a PHP script or
> >>compiled 'C' program?
> >
> >>Given a specific timezone, how do I get the time adjustment from UTC
> >>(which can vary, based on daylight savings rules)?
[...]
> I'm locked into using PHP 4 for reasons that are too long to mention here.
> The functions cited are available starting in PHP 5. Thanks, though.
>
> In the /usr/share/zoneinfo directory (I'm assuming that is what you meant),
> there are a bunch of files and directories, but they seem to have binary
> contents, and I don't know the format. Enumerating the directory tree is no
> problem, just that I don't know what is what in terms of relationship to
> UTC.
You shouldn't need to know the adjustment, just combine the directory &
file names to construct a timezone name, and use it to set the TZ
environment variable, as per this example from
<http://www.boutell.com/newfaq/creating/datestamp.html>:
<?php
putenv('TZ=America/New_York');
echo date("Y-m-d h:i:sa", time());
?>
By default, the date function of PHP also outputs the date and time
for the web server's time zone. But the putenv function changes this
by setting the effective time zone to the city we want. Linux users
can find a list of valid time zone names in the /usr/share/zoneinfo
directory (there are subdirectories for continents and so forth).
Navigation:
[Reply to this message]
|