php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43051 new DateTime doesn't work well with @timestamp and timezone
Submitted: 2007-10-20 07:35 UTC Modified: 2007-10-20 15:02 UTC
From: cezary at dodgeit dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.4 OS: Mac OS X
Private report: No CVE-ID: None
 [2007-10-20 07:35 UTC] cezary at dodgeit dot com
Description:
------------
DateTime constructor fails to work well for me when using timestamps 
and time zones.

$d = new DateTime('@1192864176', new DateTimeZone('America/
New_York'));
echo $d->format(DATE_RFC3339);
// outputs 2007-10-20T07:09:36+01:00
// why not -04:00?

$d = new DateTime('@1192864176', new DateTimeZone('Antarctica/
Vostok'));
echo $d->format(DATE_RFC3339);
// outputs 2007-10-20T07:09:36+00:00
// why not +06:00?

Besides it reports New York to be shifted +1 from UTC, it returns 
unadjusted time - it's 7 AM in UTC+1 and 7AM in UTC+0.

A timestamp is always in UTC, but the resulting DateTime should be 
adjusted according to the given time zone in my opinion.

My system clock and TZ environment variable are set to UTC.

Reproduce code:
---------------
$d = new DateTime('@1192864176', new DateTimeZone('America/
New_York'));
echo $d->format(DATE_RFC3339);

$d = new DateTime('@1192864176', new DateTimeZone('Antarctica/
Vostok'));
echo $d->format(DATE_RFC3339);


Expected result:
----------------
// 2007-10-20T03:09:36-04:00
// 2007-10-20T13:09:36+06:00

Actual result:
--------------
// 2007-10-20T07:09:36+01:00
// 2007-10-20T07:09:36+00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-20 15:02 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #43003
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 17 21:00:02 2025 UTC