note 75735 modified in function.gmmktime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 03:18:18 +0000 |
| Subject: | note 75735 modified in function.gmmktime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142048@lists.php.net to get a copy of this message | ||
Beware that despite the documentation which states is_dst is ignored, with PHP 5.2 at least, it is
not actually ignored and will cause a 1 hour offset on the UTC time returned.
This caused some interesting bugs, especially with the tzdelta function shown from previous posts
below - you need to make the final parameter a 0 instead of $ar[8] otherwise you get an
off-by-1-hour as a result.
As a result, I now use :
<?php
function tzdelta ( $iTime = 0 ) {
if ( 0 == $iTime ) { $iTime = time(); }
$ar = localtime ( $iTime );
$ar[5] += 1900; $ar[4]++;
$iTztime = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], 0);
return ( $iTztime - $iTime );
}
?>
--was--
Beware that despite the documentation which states is_dst is ignored, with PHP 5.2 at least, it is
not actually ignored and will cause a 1 hour offset on the UTC time returned.
This caused some interesting bugs, especially with the tzdelta function shown from previous posts
below - you need to make the final parameter a 0 instead of $ar[8] otherwise you get an
off-by-1-hour as a result.
As a result, I now use :
function tzdelta ( $iTime = 0 ) {
if ( 0 == $iTime ) { $iTime = time(); }
$ar = localtime ( $iTime );
$ar[5] += 1900; $ar[4]++;
$iTztime = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], 0);
return ( $iTztime - $iTime );
}
http://php.net/manual/en/function.gmmktime.php