Jon Skeet's answer is correct.
java.time
Allows you to run the same input through java.time to see the results.
Please enter a valid time zone name . Never use the abbreviation 3-4 letters, for example BST , EST or IST , as they are not real time zones, and are not standardized and not even unique (!). Therefore, we use Europe/London .
Instant class represents a moment on the timeline in UTC with a resolution of nanoseconds .
String input = "1302805253"; long millis = Long.parseLong ( input ); Instant instant = Instant.ofEpochMilli ( millis );
Apply time zone to create a ZonedDateTime object.
ZoneId zoneId = ZoneId.of ( "Europe/London" ); ZonedDateTime zdt = instant.atZone ( zoneId );
Dump for the console. We really see that Europe/London an hour ahead of UTC at this point. Thus, the time of day is 02 hours, not 01 hours. Both represent the same simultaneous moment on the timeline, they are simply viewed through the lenses of two different wall clocks .
System.out.println ( "input: " + input + " | instant: " + instant + " | zdt: " + zdt );
entrance: 1302805253 | instant: 1970-01-16T01: 53: 25.253Z | zdt: 1970-01-16T02: 53: 25.253 + 01: 00 [Europe / London]
Whole seconds
By the way, I suspect your input line represents whole seconds since the 1970 UTC era, not milliseconds. Interpreted that in a matter of seconds we get the date in 2011, in the month that this issue was published.
String output = Instant.ofEpochSecond ( Long.parseLong ( "1302805253" ) ).atZone ( ZoneId.of ( "Europe/London" ) ).toString ();
2011-04-14T19: 20: 53 + 01: 00 [Europe / London]
About java.time
The java.time framework is built into Java 8 and later. These classes supersede old inconvenient time classes such as java.util.Date , .Calendar and java.text.SimpleDateFormat .
The Joda-Time project, now in maintenance mode , advises switching to java.time.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations.
Most of the functionality of java.time is ported back to Java 6 and 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP .
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time.