rossmurphy Posted November 3, 2009 Share Posted November 3, 2009 Hi All, I have this timestamp which is sent to me but an API. It is created by java code. $timestamp = -2174688000000; I know this date is Feb 2, 1901. This converter shows me the date.. http://www.ewert-technologies.ca/online_tools/timestamp_converter.html $timestamp = -2174688000000; $timestamp /= 1000; echo date("D d M Y - H:i:s", $timestamp); But using the php date() function it gives me Dec 13th, 1901. What is going on here? Am i missing something? I have checked timezones are the same. The date was created on on a server with the same timezone. Any help would be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/ Share on other sites More sharing options...
Psycho Posted November 3, 2009 Share Posted November 3, 2009 It is a constraint with PHP. From the manual date(): Changelog: 5.1.0: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows). Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/#findComment-950550 Share on other sites More sharing options...
rossmurphy Posted November 4, 2009 Author Share Posted November 4, 2009 Thanks, that clears that issue up, i must have missed that in the manual. Here is another.. $timestamp = -116463600000; $timestamp /= 1000; echo date("D d M Y - H:i:s", $timestamp); This is returned by a java API also. Java interprets this as September 10th 1973. The above converter also does, based on GMT. But running this timestamp through PHP on a GMT based server gives September 9th 1973. Why the difference in the days? Both are run on GMT. Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/#findComment-951101 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2009 Share Posted November 4, 2009 date() use the current time zone setting and any DST offsets (which is also dependent on if your DST database that php uses is up to date.) You should be using gmdate() Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/#findComment-951173 Share on other sites More sharing options...
rossmurphy Posted November 5, 2009 Author Share Posted November 5, 2009 Even using gmdate i get the same date. Were you able to test on your own machine? $timestamp = "116463600000"; echo gmdate("M j, Y", $timestamp / 1000); Should be 10th but is showing the 9th. Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/#findComment-952048 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2009 Share Posted November 5, 2009 With php, mysql, and 2-3 online tools I found, 116463600 gives the following - php - Sep 9, 1973 23:00:00 mysql - 1973-09-09 23:00:00 http://www.epochconverter.com/ - Sun, 09 Sep 1973 23:00:00 GMT http://www.onlineconversion.com/unix_time.htm - Sun, 09 Sep 1973 23:00:00 GMT http://www.4webhelp.net/us/timestamp.php - Sunday, September 9th 1973, 23:00:00 (GMT) I would say that the web site you are using that is giving Sep. 10th is trying to do math to come up with the GMT value and is not taking into account a DST offset. Quote Link to comment https://forums.phpfreaks.com/topic/180182-java-created-time-to-php-time-using-date/#findComment-952115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.