|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-20 15:02 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 21:00:02 2025 UTC |
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