Search⌘ K
AI Features

API Features

Explore the new Java Date and Time API to understand how to use Clock for testing, work with Period and Duration for time differences, apply TemporalAdjusters for complex date calculations, handle precise time points with Instant, and manage time zones for modern, thread-safe programming.

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 ...