Edit report at https://bugs.php.net/bug.php?id=55642&edit=1
ID: 55642 Updated by: bj...@php.net Reported by: alex dot whitman at durham dot ac dot uk Summary: DateTime doesn't use default timezone -Status: To be documented +Status: Open Type: Bug Package: Date/time related Operating System: CentOS 5 PHP Version: 5.3.8 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2011-09-08 17:03:14] der...@php.net This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. @ sets the timezone to "UTC", this should be documented at http://uk3.php.net/manual/en/datetime.formats.compound.php ------------------------------------------------------------------------ [2011-09-08 14:35:30] alex dot whitman at durham dot ac dot uk Description: ------------ DateTime doesn't appear to use the default timezone (set either in php.ini or with date_default_timezone_set()). It's currently BST in the UK and without calling setTimeZone() on a DateTime object, format() will produce a date/time that is one hour behind. If setTimeZone() is called on a DateTime object then the date/time produced by format() is correct. date() by itself uses the default timezone that has been set. For consistency, DateTime should do also. Test script: --------------- <pre> <?php date_default_timezone_set('Europe/London'); $now = time(); // Initialising with a timestamp, second DateTimeZone parameter would be ignored. $dt1 = new DateTime('@' . $now); echo 'DateTime->format()', "\t", $dt1->format('Y-m-d H:i:s T Z e'); echo "\n"; $dt2 = new DateTime('@' . $now); $dt2->setTimeZone(new DateTimeZone('Europe/London')); echo 'DateTime->format()', "\t", $dt2->format('Y-m-d H:i:s T Z e'); echo "\n"; echo 'date()', "\t\t\t", date('Y-m-d H:i:s T Z e', $now); ?> <pre> Expected result: ---------------- $dt1->format() should use Europe/London as the timezone and show the correct time for that timezone. Actual result: -------------- $dt1->format() shows +00:00 as the timezone and is an hour behind. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55642&edit=1