php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72080 DateTime constructor ignoring Timezone
Submitted: 2016-04-22 18:53 UTC Modified: 2016-05-08 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: matheusmalves at gmail dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 7.0.5 OS: CentOS
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
25 + 32 = ?
Subscribe to this entry?

 
 [2016-04-22 18:53 UTC] matheusmalves at gmail dot com
Description:
------------
When I create an object (DateTime), the second parameter (timezone) is ignored and uses UTC. The test script has a comparison with PHP 5.6.

Test script:
---------------
<?php
date_default_timezone_set('UTC');

$dt = new DateTime('2016-04-22 17:00:00', new DateTimeZone('America/Sao_Paulo'));
echo $dt->getTimestamp();

// Result:
// 1461355200 (PHP 5.6.19) -> 04/22/2016 20:00 (UTC)
// 1461344400 (PHP 7.0.5)  -> 04/22/2016 17:00 (UTC)

echo '<br />';

$dt = new DateTime('2016-04-22 20:00:00', new DateTimeZone('UTC'));
$dt->setTimezone(new DateTimeZone('America/Sao_Paulo'));
echo $dt->getTimestamp();

// Result:
// 1461355200 (PHP 5.6.19) -> 04/22/2016 20:00 (UTC)
// 1461355200 (PHP 7.0.5)  -> 04/22/2016 20:00 (UTC)

Expected result:
----------------
1461355200
1461355200

Actual result:
--------------
1461344400
1461355200

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-22 19:18 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2016-04-22 19:18 UTC] requinix@php.net
https://3v4l.org/FEkCA Seems to be working fine.

You're saying that the first half of that *exact* script (though I suggest trying my tweaked version) produces the timestamp 1461344400 in PHP 7?
 [2016-04-22 19:37 UTC] matheusmalves at gmail dot com
-Status: Feedback +Status: Open
 [2016-04-22 19:37 UTC] matheusmalves at gmail dot com
Yes, the result is 1461344400. 

The function phpinfo() return this:
https://i.imgsafe.org/1779570.png
 [2016-04-22 19:40 UTC] matheusmalves at gmail dot com
Using the same code:
1461344400: 2016-04-22 17:00:00 UTC
 [2016-04-26 17:56 UTC] cmb@php.net
-Status: Open +Status: Feedback
 [2016-04-26 17:56 UTC] cmb@php.net
Which versions of the timezonedb are in use?
 [2016-05-08 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 18 06:03:37 2021 UTC