php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62704 3rd argument of DateTime::createFromFormat doesn't work
Submitted: 2012-07-31 11:35 UTC Modified: 2012-08-01 08:36 UTC
From: jachym dot tousek at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.5 OS: Windows 7 x64
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:
MUST BE VALID
Solve the problem:
49 - 21 = ?
Subscribe to this entry?

 
 [2012-07-31 11:35 UTC] jachym dot tousek at gmail dot com
Description:
------------
I thought these two commands are equal:
DateTime::createFromFormat('U', 1343730289, new DateTimeZone("Europe/Prague"))
DateTime::createFromFormat('U', 1343730289)->setTimeZone(new DateTimeZone("Europe/Prague"))

However they aren't. If that behaviour is correct (I'm unsure) can you explain why are they different?

Test script:
---------------
var_export(
DateTime::createFromFormat('U', 1343730289)->setTimeZone(new DateTimeZone("Europe/Prague"))->getTimeZone()->getName() === DateTime::createFromFormat('U', 1343730289, new DateTimeZone("Europe/Prague"))->getTimeZone()->getName()
);

Expected result:
----------------
true

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-01 08:36 UTC] salathe@php.net
For the first "command" please see the note on the DateTime::createFromFormat() 
manual page [1] which states:

  The timezone parameter and the current timezone are ignored
  when the time parameter either contains a UNIX timestamp
  (e.g. 946684800) or specifies a timezone 
  (e.g. 2010-01-28T15:00:00+02:00).

[1] http://php.net/manual/en/datetime.createfromformat.php
 [2012-08-01 08:36 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 18:01:32 2024 UTC