Doc #55642 [Opn->Csd]: DateTime doesn't use default timezone
| From: | salathe@php.net | Date: | Sat, 25 Feb 2012 16:30:12 +0000 |
| Subject: | Doc #55642 [Opn->Csd]: DateTime doesn't use default timezone | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8003@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55642&edit=1
ID: 55642
Updated by: salathe@php.net
Reported by: alex dot whitman at durham dot ac dot uk
Summary: DateTime doesn't use default timezone
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Date/time related
Operating System: CentOS 5
PHP Version: 5.3.8
-Assigned To:
+Assigned To: salathe
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2012-02-25 16:29:28] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=323519
Log: mention that @ sets the timezone to UTC (doc #55642)
------------------------------------------------------------------------
[2011-09-08 17:03:14] derick@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