|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-25 10:26 UTC] derick@php.net
-Status: Open
+Status: Wont fix
[2011-01-25 10:26 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 08:00:01 2025 UTC |
Description: ------------ I'm loading a DateTime object by a UNIX timestamp. I assumed it would use the local timezone configured (e.g. date() behavior) but it defaults to UTC. When passing a DateTimeZone object into the third parameter of DateTime::createFromFormat, it does nothing. Setting the timezone using DateTime::setTimezone after the DateTime object has loaded gives the correct result. See examples. Test script: --------------- <?php $time = 1293800400; $tz = new DateTimeZone('Australia/Sydney'); // assumes local timezone var_dump(date('r', $time)); // sets to "+00:00", should assume local timezone var_dump(DateTime::createFromFormat('U', $time)); // sets to "+00:00", ignores given DateTimeZone object var_dump(DateTime::createFromFormat('U', $time, $tz)); // adjusts to given timezone correctly var_dump(DateTime::createFromFormat('U', $time)->setTimezone($tz)); Expected result: ---------------- string(31) "Sat, 01 Jan 2011 00:00:00 +1100" object(DateTime)#2 (3) { ["date"]=> string(19) "2011-01-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } object(DateTime)#2 (3) { ["date"]=> string(19) "2011-01-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } object(DateTime)#2 (3) { ["date"]=> string(19) "2011-01-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } Actual result: -------------- string(31) "Sat, 01 Jan 2011 00:00:00 +1100" object(DateTime)#2 (3) { ["date"]=> string(19) "2010-12-31 13:00:00" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTime)#2 (3) { ["date"]=> string(19) "2010-12-31 13:00:00" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTime)#2 (3) { ["date"]=> string(19) "2011-01-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" }