php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66161 Inconsistent ISO-8601 hour offset format date_format and date('c')
Submitted: 2013-11-24 11:46 UTC Modified: 2013-11-24 21:14 UTC
From: martijn at webfauna dot nl Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.5.6 OS: Debian 4.6.3
Private report: No CVE-ID: None
 [2013-11-24 11:46 UTC] martijn at webfauna dot nl
Description:
------------
The formatting of the hour offset in date_format()/DateTime->format() differs from the one in date().
Both are correct according to the ISO-8601 specification, though I would expect a consistent format.

Test script:
---------------
date_default_timezone_set("Europe/Amsterdam");
$timeStamp = 1276592400;
$dateTest = new DateTime(date('c', $timeStamp));
echo $dateTest->format(DateTime::ISO8601) ."\n";
echo date_format($dateTest, DateTime::ISO8601)."\n";
echo date('c', $timeStamp) ."\n";

Expected result:
----------------
EITHER
1276592400
2010-06-15T11:00:00+0200
2010-06-15T11:00:00+0200
2010-06-15T11:00:00+0200

OR
1276592400
2010-06-15T11:00:00+02:00
2010-06-15T11:00:00+02:00
2010-06-15T11:00:00+02:00

Actual result:
--------------
1276592400
2010-06-15T11:00:00+0200
2010-06-15T11:00:00+0200
2010-06-15T11:00:00+02:00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-24 21:14 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-11-24 21:14 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

"c" is *an* ISO8601 date format, and so is the one represented by DateTime::ISO8601. There are plenty of different possibilities for ISO8601 formats and they are just slightly different. The constant DateTime::ISO8601 represents "Y-m-d\TH:i:sO", but nothing stops you from using ->format('c') instead. We can't change either constant/format as people might rely on it.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 15 18:01:26 2020 UTC