how can I convert a Java timestamp like this one 1335997853142
to a format that php can read?
1335997853142
should be 02 May 2012 22:30:53
Date/Time: April / 08 / 2014 12:17:42pm UTC
Java timestamp: 1396959462222
PHP timestamp: 1396959462
Dividing by 1000 doesn't give exactly the right answer because it will give a double or float value, i.e. 1396959462.222 which is not what we want. We need an integer here like 1396959462. So correct way to convert Java timestamp to PHP timestamp would be by using intval():
$php_timestamp = intval($java_timestamp/1000);
In a real example, in one of my Android apps where I send Java timestamp to a PHP server, I do it as mentioned above. Also, for good security practice, I add a preg_replace() to make sure if someone added hack code in this field, it is removed:
$php_timestamp = intval(preg_replace('/[^0-9]/', '', $java_timestamp)/1000);
PHP timestamps are seconds, not milliseconds.
echo gmdate("d M Y H:i:s",1335997853);
That outputs 02 May 2012 22:30:53
.
date need a timestamp in integer format. So I think U should remove 3 last number. Not use division beause it will return float number.
The timestamp you have is in milliseconds when it should be in seconds
$java_time = 1335997853142;
$php_time = $java_time / 1000;
$today = date("d M Y G:i:s", $php_time);
Output
02 May 2012 22:30:53
It's a timestamp in microtime
Use
$time = date("whatever you need", $javatime / 1000);
Use the date() function in php, the parameters are found here: http://php.net/manual/en/function.date.php