|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2012-11-05 16:35 UTC] sea128 at post dot cz
 Description:
------------
DateTime::getTimestamp() returns different value from DateTime::setTimestamp().
Problem is caused by time zone where is used daylight saving and time when timezone offset is switched.
Test script:
---------------
$tz = new DateTimeZone('Europe/Prague');
$date = new DateTime('now',$tz);
$date->setTimestamp(1351386000);
echo $date->getTimestamp() . "\n";
$date->setTimestamp(1351386000-3600);
echo $date->getTimestamp() . "\n";
Expected result:
----------------
1351386000
1351382400
Actual result:
--------------
1351386000
1351386000
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Thu Oct 30 22:00:01 2025 UTC | 
There's some other strangeness here also. Consider: $tz = new DateTimeZone('Europe/Paris'); $dt = new DateTime('2014-10-26T02:30', $tz); echo $dt->format(DateTime::ISO8601) . " (" . $dt->getTimeStamp() . ")\n"; $ts = $dt->getTimeStamp() - 3600; $dt = new DateTime("@$ts", new DateTimeZone('UTC')); $dt->setTimeZone($tz); echo $dt->format(DateTime::ISO8601) . " (" . $dt->getTimeStamp() . ")\n"; OUTPUT: 2014-10-26T02:30:00+0100 (1414287000) 2014-10-26T02:30:00+0200 (1414287000) So even though going through UTC fixed the offset shown in the formatting, it still adjusted the timestamp. The second value should have the timestamp 141283400. This is a really dangerous bug that has been sitting for too long. Please raise priority. Thanks.