API Features
Learn about the features included in the date and time API.
Clock
The Clock
can be used in conjunction with dates and times to help build your tests. During production, a normal Clock
can be used, and then a different one is used during tests.
To get the default clock, use the following:
Clock.systemDefaultZone();
The Clock
can then be passed into factory methods. For example:
LocalTime time = LocalTime.now(clock);
Period and Duration
Java 8 has two types for representing time differences as humans understand them: Period and Duration.
Period is a date-based amount of time, such as “2 years, 3 ...
Access this course and 1400+ top-rated courses and projects.