Java 8 introduced a new Date-Time API based on IS0-8601 date-time standards.
The Date-Time API uses the calendar system defined in ISO-8601 as the default calendar. This calendar is based on the Gregorian calendar system
The LocalDateTime, ZonedDateTime, and OffsetDateTime in the Date-Time API are all using ISO calendar system.
The Date-Time API uses the Unicode Common Locale Data Repository (CLDR) for the locale data.
The Date-Time API uses the Time-Zone Database (TZDB) for information about time zone.
The methods in the API are well defined
The Date-Time API provides a fluent interface which makes the code easy to read. Method calls can be chained together. For example we can use the following code to create new date.
LocalDate aDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).minusDays(2);
The Java Date-Time API consists of mostly immutable classes. After the object is created, it cannot be modified. To change its value, a new object must be created as a modified copy of the original.
The Date-Time API is thread-safe.
Methods used to create date or time objects are prefixed
with, rather than constructors.
There are no
set methods. For example:
LocalDate dateOfBirth = LocalDate.of(2014, Month.MAY, 14);
The Date-Time API is extensible wherever possible.
Java Date-Time API has a separate set of classes to deal with machine-based time and calendar-based human time.
Java Date-Time API consists of the primary package,
java.time, and four subpackages:
java.timecontains the core of the API for representing date and time. It includes classes for date, time, date and time combined, time zones, instants, duration, and clocks.
LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration, and Instantclasses are in this package. Classes in this package are based on ISO-8601 standards.
java.time.chronocontains the API for representing calendar systems other than the default ISO-8601. For example, Hijrah calendar, ThaiBuddhist calendar, etc.
java.time.formatcontains classes for formatting and parsing dates and times.
java.time.temporalcontains API allowing interoperations between the date and time classes, querying, and adjustment. For example, TemporalField and ChronoField and TemporalUnit and ChronoUnit.
java.time.zonecontains classes that support time zones, offsets from time zones, and time zone rules. For example, ZonedDateTime, and ZoneId or ZoneOffset.