note 14203 added to function.localtime.php
| From: | verdy_p at wanadoo dot fr | Date: | Sun, 22 Jul 2001 09:23:50 +0000 |
| Subject: | note 14203 added to function.localtime.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15660@lists.php.net to get a copy of this message | ||
The corresponding function call to get the GMT time is not specified here. Only local time is
reported, according to the current TZ environment setting.
One could try to use putenv() to set another timezone temporarily, however when running PHP in safe
mode, putenv() is disabled and cannot be used in scripts.
However it's possible to simulate gmttime() by using localtime() and by transforming the
results in the returned array.
The biggest problem with this function is that it is using an OS-dependent and localtime() function
which is also depending on the standard C library implementation (some of them, do not support
accurate locales). The second problem is that localtime() does not return an index specifying the
local timezone offset, so transforming this date to UTC will become very ugly. Some systems support
the gmtime() C function call, some don't. To get the timezone, some C libraries provide a
global _timezone variable, some provide it as a macro that use a function call, some do not provide
any variable, and one must deduce it by interpreting the TZ environment. This is too much ugly for
PHP.
PHP should be extended by adding support to gmttime() with the same parameters, but the returned
array should include additional indices to store the timezone offsets in seconds and names for both
standard time and DST, for example:
[tz_offset_std] = 3600,
[tz_offset_dst]= 7200,
[tz_name_std] = 'CET', (GMT+01:00)
[tz_name_dst] = 'CEDT'. (GMT+02:00)
Or for the international, locale-independant, Zulu time (also known as UCT or simply UT), returned
by gmtime():
[tz_offset] = 0,
[tz_offset_dst]= 0,
[tz_name] = 'Z',
[tz_name_dst] = 'Z'.
But it's much easier to use PHP's date() and gmdate() to make such transformations.
Beware of DST rules! In the southern hemisphere, standard time still occurs during winter, but the
southern Winter is in June, not in December ! Use the tm_isdst indicator to know which timezone to
display or interpret !
http://www.php.net/manual/en/function.localtime.php