Java converting unix timestamp to wrong time
I have a unix timestammp stored in mysql. I will transform it in time. It displays the wrong time.
Here is the 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 a variable that contains the unix timestamp.
Example: for timestamp=1417437428505
it should show 6:07 pm and show 12:31 am
What is this solution?
+3
source to share
3 answers