Clock fixed(Instant fixedInstant, ZoneId zone)
returns a clock that always returns the same instant.
fixed
has the following syntax.
public static Clock fixed(Instant fixedInstant, ZoneId zone)
The following example shows how to use fixed
.
import java.time.Clock; import java.time.Instant; import java.time.ZoneId; // w ww .j a va 2s . 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.