|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-09-08 17:03 UTC] derick@php.net
-Status: Open
+Status: To be documented
[2011-09-08 17:03 UTC] derick@php.net
[2011-09-12 10:37 UTC] bjori@php.net
-Status: To be documented
+Status: Open
[2011-09-12 10:37 UTC] bjori@php.net
-Type: Bug
+Type: Documentation Problem
[2012-02-25 16:29 UTC] salathe@php.net
[2012-02-25 16:30 UTC] salathe@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: salathe
[2012-02-25 16:30 UTC] salathe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 12:00:01 2025 UTC |
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.