java.time · java.base · since Java 1.8

Clock

declaration
public abstract class Clock implements InstantSource

An injectable time source: fixed, offset, or system clocks. Passing a Clock instead of calling now() makes time-dependent logic deterministic under test.

Key methods

static Clock systemUTC() / systemDefaultZone()Production clocks.
static Clock fixed(Instant fixed, ZoneId zone)Frozen time for tests.
Instant instant()The current reading.