tl;dr
Instant.ofEpochMilli( 1_372_916_493_000L ) // Moment on timeline in UTC.
2013-07-04T05:41:33Z
…and…
Instant.ofEpochMilli( 1_372_916_493_000L ) // Moment on timeline in UTC.
.atZone( ZoneId.of( "Europe/Berlin" ) ) // Same moment, different wall-clock time, as used by people in this region of Germany.
2013-07-04T07:41:33+02:00[Europe/Berlin]
Details
You are using troublesome old date-time classes now supplanted by the java.time classes.
java.time
If you have a count of milliseconds since the epoch reference date of first moment of 1970 in UTC, 1970-01-01T00:00Z, then parse as an Instant
. The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
Instant instant = Instant.ofEpochMilli( 1_372_916_493_000L ) ;
instant.toString(): 2013-07-04T05:41:33Z
To see that same simultaneous moment through the lens of a particular region’s wall-clock time, apply a time zone (ZoneId
) to get a ZonedDateTime
.
ZoneId z = ZoneId.of( "Europe/Berlin" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
zdt.toString(): 2013-07-04T07:41:33+02:00[Europe/Berlin]
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?