Clock fixed(Instant fixedInstant, ZoneId zone) example

Description

Clock fixed(Instant fixedInstant, ZoneId zone) returns a clock that always returns the same instant.

Syntax

fixed has the following syntax.


public static Clock fixed(Instant fixedInstant,   ZoneId zone)

Example

The following example shows how to use fixed.


import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
//  ww  w .  j av a2s  .c  o m
public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.now();
    Clock newClock = Clock.fixed(instant,ZoneId.systemDefault());
    
    System.out.println(newClock.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