Java Date Time - Clock system(ZoneId zone) example








Clock system(ZoneId zone) returns a clock that returns the current instant using best available system clock.

Syntax

system has the following syntax.

public static Clock system(ZoneId zone)

Example

The following example shows how to use system.

import java.time.Clock;
import java.time.ZoneId;
/*from  w w  w. java2 s. c o  m*/
public class Main {
  public static void main(String[] args) {
    Clock clock = Clock.system(ZoneId.systemDefault());
    System.out.println(clock);
    System.out.println(clock.instant());
  }
}

The code above generates the following result.