note 94848 deleted from datetime.settimestamp by danielc
| From: | danielc@php.net | Date: | Sat, 24 Apr 2010 20:47:37 +0000 |
| Subject: | note 94848 deleted from datetime.settimestamp by danielc | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168599@lists.php.net to get a copy of this message | ||
Note Submitter: julien_muetton at carpe-hora dot com
----
Hi there,
if you use previous code on x64 architecture and got a php version prior to 5.2.7 (debian lenny for
instance), beware of bug #45038 (http://bugs.php.net/bug.php?id=45038)
a solution can be to use following code:
<?php
function setTimestamp($timestamp) {
$thisz_original = $this -> getTimezone()->getName();
$thisz_utc = new DateTimeZone('UTC');
$this -> setTimezone($thisz_utc);
$year = gmdate("Y",$timestamp);
$month = gmdate("n",$timestamp);
$day = gmdate("j",$timestamp);
$hour = gmdate("G",$timestamp);
$minute = gmdate("i",$timestamp);
$second = gmdate("s",$timestamp);
$this -> setDate($year,$month,$day);
$this -> setTime($hour,$minute,$second);
$this -> setTimezone(new DateTimeZone($thisz_original));
}
?>