Clock system(ZoneId zone) example

Description

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 .j  av  a  2 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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset