The Clock class was added in Java 8 and provides access to an instant in time using the best available system clock, and to be used as a time provider which can be effectively stubbed for testing purposes.

Instances of this class are used to find the current instant, which can be interpreted using the stored time-zone to find the current date and time. As such, a clock can be used instead of System.currentTimeMillis() and TimeZone.getDefault().

Clock Class Diagram

The below class diagram shows a list of methods that the Clock class provides.

Java Clock Class Methods/APIs with Examples

Let's explore a few important and commonly used Clock methods with examples.