Date-Time API Design Principles

Description

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 of, from, or 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.





















Home »
  Java Date Time »
    Tutorial »




Java Date Time Tutorial