Sulaiman
Sulaiman

Reputation: 506

what is the difference betwen timestamp in java and php?

I have a java file that write records to the DB and time stamps

I have another php file that reads that records..

unfortunately After converting the time stamp to dates I got a wrong dates ??

what is the problem !!!

Upvotes: 1

Views: 1822

Answers (3)

karim79
karim79

Reputation: 342655

I think the problem is you're retrieving a DATETIME or TIMESTAMP column or such that has been stored and screwing up the conversion. Try this:

$phpdate = strtotime( $dateFromDb );
echo date("F j, Y, g:i a", $phpdate);    

Upvotes: 0

tschaible
tschaible

Reputation: 7695

Java uses a timestamp which is milliseconds from the epoch. PHP uses the standard unix timestamp which is seconds from the epoch.

I believe both use the same epoch of Jan. 1, 1970 00:00:00 UTC

Upvotes: 10

gargantuan
gargantuan

Reputation: 8944

PHP uses the UNIX epoch, I suspect Java uses a different epoch.

EDIT: I was way off, turns out PHP uses seconds, java uses miliseconds. So multiply by 1000 or divide by 1000 depending on which way you're converting.

Upvotes: 2

Related Questions