php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63459 getTimestamp() affected by setTimezone() on DST transition
Submitted: 2012-11-07 21:12 UTC Modified: 2017-03-19 10:53 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:4 of 5 (80.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: luttkens at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 7.1 OS: Any
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:
27 + 34 = ?
Subscribe to this entry?

 
 [2012-11-07 21:12 UTC] luttkens at gmail dot com
Description:
------------
getTimestamp() is supposed to return the time in UNIX-timestamp. To my 
understanding a unix timestamp is always in UTC and not affected by the timezone.

That is; regardless the the timezone, getTimestamp() should return the same value 
for any date. In most cases it does, but not on daylight-saving-time (DST) 
transitions.

I have create a short script that illustrates the problem.

Test script:
---------------
$date1 = new DateTime("@1351382400"); // Sun Oct 28 2012 02:00:00 GMT+2 (DST)
var_dump($date1->getTimestamp()); //prints: 1351382400
$date1->setTimezone(new DateTimeZone("Europe/Stockholm"););
var_dump($date1->getTimestamp()); //prints: 1351386000


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-24 12:09 UTC] ryan dot scudellari at bronto dot com
I too have run into this issue with PHP versions 5.3.23 and 5.3.6
 [2014-01-14 00:38 UTC] jeremy at jcarnus dot fr
Hello,

I have the same problem with timestamp 1382833659 that return 1382837259 on php 5.4.4

Does a fix will be released ?

Thanks
 [2017-01-16 06:39 UTC] heiglandreas@php.net
-PHP Version: 5.4.7RC1 +PHP Version: 7.1
 [2017-01-16 06:39 UTC] heiglandreas@php.net
Somethings is different between format('U') and getTimeStamp().

The format('U') returns the correct timestamp whereas getTimestamp returns a wrong one.

See https://3v4l.org/cVRBI
 [2017-03-19 10:53 UTC] heiglandreas@php.net
-Status: Open +Status: Duplicate
 [2017-03-19 10:53 UTC] heiglandreas@php.net
As this is related to the DSTchange back from DST to StandardTime we're now tracking this in https://bugs.php.net/bug.php?id=74274
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC