Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert java timestamp to php timestamp?

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.

But what ever I try I get errors or PHP says 1970-01-01 01:00:00 or 2038-01-19 04:14:07

PLS help!!! I'm searching for over 1.5h for a soloution!

like image 961
user1373728 Avatar asked May 03 '12 22:05

user1373728


2 Answers

PHP timestamps are seconds, not milliseconds.

echo gmdate("d M Y H:i:s",1335997853);

That outputs 02 May 2012 22:30:53.

like image 186
Mark Reed Avatar answered Oct 10 '22 12:10

Mark Reed


it is not a java timestamp, it is milliseconds since epoch (1970-01-01 00:00:00 GMT)

Which php supports too except in seconds so the following should work in php:

date('choose your format', javaMilliseconds / 1000);
like image 36
pstanton Avatar answered Oct 10 '22 12:10

pstanton