|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61171 Ambiguous 'timezone' parameter description causes hair-pulling
Submitted: 2012-02-23 18:54 UTC Modified: 2012-11-15 09:38 UTC
From: chichilatte at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 - 32 = ?
Subscribe to this entry?

 [2012-02-23 18:54 UTC] chichilatte at gmail dot com
From manual page:
The timezone parameter is described as "A DateTimeZone object representing the 
desired time zone". This is really ambiguous, since it depends on the user's 
motivation for creating the DateTime object. For instance, I wanted to display a 
UTC date string as a UK date string, so my "desired" timezone was 
"Europe/London". That's not how it works, but because it says "desired", that's 
how it sounds like it works. 

This sounds insignificant really, but I wasted an hour figuring out why it 
wasn't working (date problems are tough because dates are affected by absolutely 
everything in a system!), and I'm sure many other people have encountered the 
same problem.

I suggest the timezone parameter should be described as "A DateTimeZone object 
representing the timezone of the time parameter".


Test script:
// What someone would do who "desired" to convert a date from UTC to UK time...

$dateTime = new DateTime('2012-05-01 23:00:00UTC', 'Europe/London');
echo $dateTime->format("Y-m-d H:i:s e");
// produces...
// 2012-05-01 23:00:00 UTC

// The actual way to do it...
$dateTime = new DateTime('2012-05-01 23:00:00UTC');
$dateTime->setTimezone(new DateTimeZone('Europe/London'));
echo $dateTime->format("Y-m-d H:i:s e");
// produces...
// 2012-05-02 00:00:00 Europe/London


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-15 09:38 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2012-11-15 09:38 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 18:01:33 2024 UTC