php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46641 Timezone format inconsistencies between date() and DateTime::format()
Submitted: 2008-11-21 17:46 UTC Modified: 2008-11-22 16:45 UTC
From: cross+php at distal dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5CVS, 6CVS (2008-11-21) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cross+php at distal dot com
New email:
PHP Version: OS:

 

 [2008-11-21 17:46 UTC] cross+php at distal dot com
Description:
------------
When using some of the timezone output format characters, notably "e" and "T", produce different results on a DateTime built from a string time and calling date() on the results of strtotime().

Reproduce code:
---------------
<?php
$timestr = "2008-11-19 10:51:35.199665-05";

$outformat = "M j Y H:i:s T (e,I,O,P,T,Z)";

$obj = new DateTime($timestr);

print date($outformat, strtotime($timestr)) . "\n";
print $obj->format($outformat) . "\n";

?>


Expected result:
----------------
Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000)
Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000)


Actual result:
--------------
Nov 19 2008 10:51:35 EST (America/New_York,0,-0500,-05:00,EST,-18000)
Nov 19 2008 10:51:35 GMT-0500 (-05:00,0,-0500,-05:00,GMT-0500,-18000)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-22 11:27 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected. Without converting to an integer with strtotime(), the DateTime object remembers which timezone it was created with. In this case the timezone it knows is "GMT-0500". If you use date(), this information is not available and it will use the default timezone. The following example shows this a bit better:

derick@kossu:/tmp$ cat bug46641.php 
<?php
date_default_timezone_set('Europe/Oslo');
$timestr = "2008-11-19 10:51:35.199665-05";

$outformat = "M j Y H:i:s T (e,I,O,P,T,Z)";

$obj = new DateTime($timestr);

print date($outformat, strtotime($timestr)) . "\n";
print $obj->format($outformat) . "\n";

?>

derick@kossu:/tmp$ php bug46641.php
Nov 19 2008 16:51:35 CET (Europe/Oslo,0,+0100,+01:00,CET,3600)
Nov 19 2008 10:51:35 GMT-0500 (-05:00,0,-0500,-05:00,GMT-0500,-18000)

 [2008-11-22 16:45 UTC] cross+php at distal dot com
Okay.  I can see this point, and thought something like that was 
involved, the transition through a timestamp.

However, I would still like to know how to get 'T' (and 'e') to return 
what I expect.  For example, I'd rather see 'EDT' than 'GMT-0500', and 
I still feel that '-05:00.0' instead of the expected long name may in 
fact be a [different] bug/error.

Do you know how I can resolve this?  It seems that setting the 
timezone of the DateTime causes the results of the 'T' and 'e' 
formatting parameter to work as expected.  If I set the timezone to date_default_timezone_get, or assumedly anything else, it will return 
the format I expect for 'e' and 'T'.

Is that the correct thing I should do to get the behaviour I expected?

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Sep 19 13:00:02 2025 UTC