Java Date Time - Clock systemUTC() example








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

This clock, rather than systemDefaultZone(), should be used to get current instant without the date or time.

Syntax

systemUTC has the following syntax.

public static Clock systemUTC()

Example

The following example shows how to use systemUTC.

import java.time.Clock;

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

The code above generates the following result.