Android datetime to MySQL datetime via PHP

I use php line:

date("Y-m-d H:i:s", $timestamp);

to transform date and time for MySQL DB DATETIME field

where $timestamp var has timestamp sent over from Android, which is obtained by:

new java.util.Date().getTime();

Now, Android returns, say, not so recently '1394398765798', which should be, based on documentation, current timestamp

My problem was that I couldn't get the value into the database, so I decided to see what the timestamp actually is by using this website and it gave me not expected value: 46156-09-26 14:29:58.

So I found the problem.. But my question is whether PHP (I am an amateur) has its timestamps not starting from 1970.. or what could be the problem? Maybe I use wrong approach to solve my problem..


PHP's time() method returns seconds.

Java's Date.getTime() returns milliseconds.

To convert from PHP to Java, multiply by 1000. Likewise, to get the reverse, divide by it.

If you're going to use the date as an identifier as well, I would highly suggest normalizing it across both platforms so that they are synchronous and can link up correctly (ie. whenever getting the time in Java, you should always divide by 1000 and re-multiply it back by 1000 before saving it to your app's local database (which will 000 it out for you), this way the values would always be in sync with the server's database).

Ok, I found out that the timestamp in PHP is actually shorter than the timestamp of

new java.util.Date().getTime();

when I get rid of 3 last digits, I get datetime which is 1 hour and some minutes shorter than Android timestamp

Need Your Help

how to find all global variables at runtime?

c visual-studio-2008

I've a very large C program consisting of hundred of files; I want to