Java Date Time - Clock systemDefaultZone() example








Clock systemDefaultZone() returns a clock for the current instant using the best available system clock, converting to date and time using the default time-zone.

The UTC clock should be used when you need the current instant without the date or time.

Syntax

systemDefaultZone has the following syntax.

public static Clock systemDefaultZone()

Example

The following example shows how to use systemDefaultZone.

import java.time.Clock;

public class Main {
  public static void main(String[] args) {
    Clock clock = Clock.systemDefaultZone();
    System.out.println(clock);
    System.out.println(clock.instant());
  }
}

The code above generates the following result.