Clock systemUTC() example

Description

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;
//from w  w  w  . j  ava2 s .c  o  m
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.





















Home »
  Java Date Time »
    java.time Reference »




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