3

I have unix timestammp stored in mysql. I am converting it into time. It displays wrong time.

Here is code:

Date date = new Date((long)timestamp*1000); 
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); 
sdf.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
timeString = sdf.format(date);
System.out.println(timeString);`

timestamp is variable which contains unix timestamp.
Ex: for timestamp=1417437428505 it should show 6:07 PM and showing 12:31 AM

What is solution for it?

0

3 Answers 3

4

You're multiplying a timestamp which is already in milliseconds since the Unix epoch by 1000. You just want:

Date date = new Date(timestamp);

If you look at all of the date, not just the time, you'll see it's currently in 46886!

Sign up to request clarification or add additional context in comments.

Comments

1

Are You sure that need multiplied by 1000? I tried pass without multiplying Date date = new Date(timestamp); and it printed 6:07 PM

Comments

0

Remove multiply with 1000 in

Date date = new Date((long)timestamp*1000);

than it works.

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.