Clock offset(Clock baseClock, Duration offsetDuration) example
Description
Clock offset(Clock baseClock, Duration offsetDuration)
gets a clock that
returns instants from the specified clock with the specified duration added.
The duration can be negative.
Syntax
offset
has the following syntax.
public static Clock offset(Clock baseClock, Duration offsetDuration)
Example
The following example shows how to use offset
.
import java.time.Clock;
import java.time.Duration;
//from w w w . j a v a2 s .c o m
public class Main {
public static void main(String[] args) {
Clock clock = Clock.systemUTC();
Duration duration = Duration.ofHours(3);
Clock newClock = Clock.offset(clock,duration);
System.out.println(newClock.instant());
}
}
The code above generates the following result.