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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 03 12:01:42 2024 UTC