Skip to content

JavaDate

Thomas Czogalik edited this page May 13, 2020 · 1 revision

source

Instant

  • represents a moment, a specific point in the timeline.
  • a count of nanoseconds since the epoch of the first moment of 1970 UTC

Instant instant = Instant.now() ; // Capture the current moment in UTC.

LocalDateTime

represents a date and a time-of-day. But lacking a time zone or offset-from-UTC, this class cannot represent a moment. It represents potential moments along a range of about 26 to 27 hours, the range of all time zones around the globe.

ZoneId

  • A time zone is represented by the ZoneId class.
  • A time zone is a set of rules for handling adjustments and anomalies as practiced by a local community or region.

ZoneId z = ZoneId.of( “Africa/Tunis” ) ;

ZonedDateTime

  • ZonedDateTime = ( Instant + ZoneId )

ZonedDateTime zdt = ZonedDateTime.now( z ) ; // Pass a `ZoneId` object such as `ZoneId.of( "Europe/Paris" )`.

java.util.Date

tries to be an instant and dateTime at same time and does both poorly

  • It doesn’t have a time zone.
  • It doesn’t have a format.
  • It doesn’t have a calendar system.
  • It rates years as two digits since 1900.
  • Months are zero indexed (0 – January, 11 – December)
  • All classes in this old API are mutable.
Clone this wiki locally