Instant.ofEpochMilli( 1_522_899_000_000L )
The modern approach uses the java.time classes that supplant the troublesome old legacy classes (
Your input seems to be a count of milliseconds since the epoch of 1970-01-01T00:00Z. Sometimes known as Unix time, though not definitively.
long input = 1_522_899_000_000L ; Instant instant = Instant.ofEpochMilli( input );
If your input is textual, parse as a number with
long input = Long.parseLong( "1522899000000" ) ; Instant instant = Instant.ofEpochMilli( input );
Instant is always in UTC, by definition. If you want to see that same moment through the wall-clock time used by people of a certain region (a time zone), apply a
ZoneId to get a
Specify a proper time zone name in the format of
continent/region, such as
Pacific/Auckland. Never use the 3-4 letter pseudo-zones such as
IST as they are not true time zones, not standardized, and not even unique(!).
ZoneId z = ZoneId.of( "Pacific/Auckland" ) ; ZonedDateTime zdt = instant.atZone( z ) ;
The strings generated above are in standard ISO 8601 format. For other formats, search Stack Overflow for the
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as
YearQuarter, and more.