php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65608 Possible problems with the UNIX timestamp
Submitted: 2013-09-03 08:28 UTC Modified: 2013-09-04 02:47 UTC
From: jiri dot kapinus at gmail dot com Assigned:
Status: Not a bug 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:
MUST BE VALID
Solve the problem:
9 + 6 = ?
Subscribe to this entry?

 
 [2013-09-03 08:28 UTC] jiri dot kapinus at gmail dot com
Description:
------------
The UNIX timestamp gives the number of seconds since January 1 1970 00:00:00 UTC. 
But value of UNIX timestamp can be different, that in really is. More information 
on http://www.najdouvas.cz/unix-timestamp-error/

Test script:
---------------
<?php
date_default_timezone_set('UTC');
echo "Current time and date in UTC timezone: " . date("M d Y H:i:s", time()) . "<br>";
date_default_timezone_set('America/Kentucky/Monticello');
echo "Current time and date in America/Kentucky/Monticello timezone: " . date("M d Y H:i:s", time()) . "<br>";
echo "UNIX timestamp defined by Strtotime for now: " . strtotime("now")  . " <br>";
$start = strtotime("now");
$zonestart = date("M d Y H:i:s", 00);
echo "UNIX timestamp start at: Jan 01 1970 00:00:00 UTC<br>";
echo "when convert this time to America/Kentucky/Monticello, it returns following date for Monticello timezone<br>";
echo "UNIX timestamp start at:   " . $zonestart . " America/Kentucky/Monticello timezone<br>";
echo "To this date we add UNIX timestamp for NOW time. The result may be the same as the current time and date for America/Kentucky/Monticello <br>";
$date = date_create($zonestart);
$date->modify('+ ' . $start . ' sec');
echo "Result is: " . $date->format('M d Y H:i:s e') . "<br>";
date_default_timezone_set('UTC');
$date->setTimezone(new DateTimeZone("UTC")); 
echo "Changing this time to UTC timezone: " . $date->format('M d Y H:i:s e') . "<br><br>";
echo "When final date is not the same as the date at the begining, it means, that the UNIX timestamp don't give up exact number of second for this place or timezone. The UNIX timestamp gives the number of seconds since January 1 1970 00:00:00 UTC. But it's different for different places.<br><br>";
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-03 08:45 UTC] jiri dot kapinus at gmail dot com
instead of ,,when convert this time to America/Kentucky/Monticello, it returns 
following date for Monticello timezone" 

is right this: 

,,when we set the time with parametr UNIX timestamp 0, it returns UNIX timestamp 
start time for Monticello timezone"
 [2013-09-04 02:47 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-09-04 02:47 UTC] rasmus@php.net
I don't understand what you think the bug is here. Of course you can't just add 
the timestamp to the starting date for Unix time and expect it to work for all 
timezones. It completely ignores daylight savings along the way. If you can 
explain yourself better using a single timezone and prove that what you are 
seeing isn't simply the effect of daylight savings you can re-open this.
 [2013-09-04 14:51 UTC] anon at anon dot anon
The "bug" emerges from the assumption that if you take a time in time zone A, offset it by some amount, and then convert it to time zone B; you would get the same result as converting it to time zone B first, and then offsetting it.

Unfortunately, that assumption isn't true. Monticello used to be on Central Time. Now it's on Eastern Time.

It's definitely annoying, but it's not a bug in PHP. Time is HARD. For more pitfalls, see:
* http://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time
* http://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time-wisdom
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC