Summary
It appears that the number 1522899000000
represents the count of milliseconds since the epoch reference of 1970-01-01T00:00:00Z, the beginning of 1970 in UTC.
Instant.ofEpochMilli( 1_522_899_000_000L )
This translates to: 2018-04-05T03:30:00Z
Utilizing java.time
The recommended approach is to utilize the java.time classes instead of the outdated Date
, Calendar
, and SimpleDateFormat
classes.
If your input signifies milliseconds since the epoch of 1970-01-01T00:00Z, you can interpret it as an Instant
. The Instant
class defines a moment on the UTC timeline with nanosecond precision.
long input = 1_522_899_000_000L ;
Instant instant = Instant.ofEpochMilli( input );
The instant is represented as: 2018-04-05T03:30:00Z
If your input is in text form, you can convert it to a number using Long.parse
.
long input = Long.parseLong( "1522899000000" ) ;
Instant instant = Instant.ofEpochMilli( input );
ZonedDateTime
An Instant
is always in UTC but can be viewed in a specific time zone by creating a ZonedDateTime
object.
To obtain the time in a particular region's time zone, specify a valid time zone in the format of continent/region
, such as America/Montreal
or Pacific/Auckland
.
ZoneId z = ZoneId.of( "Pacific/Auckland" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
The adjusted time in the specified time zone is: 2018-04-05T15:30+12:00[Pacific/Auckland]
DateTimeFormatter
The timestamps generated adhere to the ISO 8601 standard. For alternative formats, refer to Stack Overflow for guidance on using the DateTimeFormatter
class.
Introduction to java.time
The java.time framework is integrated into Java versions 8 and above. These classes replace outdated date-time classes like java.util.Date
, Calendar
, and SimpleDateFormat
.
For further information, consult the Oracle Tutorial and explore examples on Stack Overflow. The specification for these classes is outlined in JSR 310.
Direct database interaction using java.time objects is supported. For JDBC drivers compliant with JDBC 4.2 or later, strings or java.sql.*
classes are no longer necessary.
Wondering where to find the java.time classes?
- Java SE 8 and beyond: bundled within the standard API
- Java SE 6 and 7: ThreeTen-Backport provides back-ported functionality
- Android: newer Android versions contain implementations, while older versions can utilize ThreeTenABP
The ThreeTen-Extra project extends java.time with additional classes to enhance its capabilities.