Conversion from Unix Time to Java Calendar

calendar, java, unix-timestamp

Solution

Java works with millisecond timestamps, while Unix time stamps are typically measured in seconds. Multiply the Unix timestamp by `1000L` to get the right time.

Problem

The following is driving me crazy, why am I getting the wrong calendar date when converting Unix Time 1386230874 using the code below!! This should be Thu Dec 5 19:07:54 2013 Output: ``` Comment posted on:Sat Jan 17 11:03:50 EST 1970 ``` Code: ``` Calendar facebook_created_time_calendar = Calendar.getInstance(TimeZone.getTimeZone("Australia/Sydney")); facebook_created_time_calendar.setTimeInMillis(1386230874); out.print("Comment posted on:"); out.println(facebook_created_time_calendar.getTime()); ```

Original source