1

I get Integer timestamp from PHP program, but in Java timestamps are ing Long format. So how can I convert this PHP Integer timestamp to Java Long format and convert that long format to Date object?

2 Answers 2

1

PHP timestamp is number of seconds since 1/1/1970, and Java timestamp is number of milliseconds since 1/1/1970. So all you need to do in Java is multiply it by 1000.

Date d=new Date((long)phpTimeStamp*1000);
Sign up to request clarification or add additional context in comments.

3 Comments

Problem is that when I multiply Integer by 1000, it will overflow, so Is it possible to convert first to long and then multiply wiht 1000?
Now I got it workign, first convert to long and then multiply with 1000
but now it multiplies Integer value by 1000 and after that it converts it to long, it should convert it first to long and then multiply. Like this => ((long)phpTimeStamp)*1000
0

To avoid overflow:

Date d=new Date(((long)phpTimeStamp)*1000);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.