|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: chichilatte at gmail dot com
New email:
PHP Version: OS:


 [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: Mon May 20 19:01:33 2024 UTC