php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61028 DateTime constructor ignores Timezone info in DATE_ISO8601 formated strings
Submitted: 2012-02-09 15:04 UTC Modified: 2012-02-09 15:18 UTC
From: tom dot anheyer at berlinonline dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.10 OS: OpenSuse 12.1
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: tom dot anheyer at berlinonline dot de
New email:
PHP Version: OS:

 

 [2012-02-09 15:04 UTC] tom dot anheyer at berlinonline dot de
Description:
------------
DateTime ignores Timezone:

php -r '$d=new DateTime("2012-02-09T15:30:14+0100"); echo $d->format(DATE_ISO8601)."\n"; $d=new DateTime("2012-02-09T14:30:14+0000"); echo $d->format(DATE_ISO8601)."\n";'

Output:
2012-02-09T15:30:14+0100
2012-02-09T14:30:14+0000


strtotime works as expected:

php -r 'echo date(DATE_ISO8601, strtotime("2012-02-09T15:30:14+0100"))."\n"; echo date(DATE_ISO8601, strtotime("2012-02-09T14:30:14+0000"))."\n";'

Output:
2012-02-09T15:30:14+0100
2012-02-09T15:30:14+0100


Test script:
---------------
php -r '$d=new DateTime("2012-02-09T15:30:14+0100"); echo $d->format(DATE_ISO8601)."\n"; $d=new DateTime("2012-02-09T14:30:14+0000"); echo $d->format(DATE_ISO8601)."\n";'


Expected result:
----------------
2012-02-09T15:30:14+0100
2012-02-09T15:30:14+0100


Actual result:
--------------
2012-02-09T15:30:14+0100
2012-02-09T14:30:14+0000


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-09 15:18 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

DateTime objects actually keep their timezone information, whereas strtotime() removes it (as a timestamp doesn't contain tz info).
 [2012-02-09 15:18 UTC] derick@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 09:01:27 2025 UTC