Clock systemDefaultZone() example

Description

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;
// www  . j av a  2  s  .c o  m
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.





















Home »
  Java Date Time »
    java.time Reference »




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