Clock tick(Clock baseClock, Duration tickDuration)
returns a clock
truncated to the nearest occurrence of the specified duration.
tick
has the following syntax.
public static Clock tick(Clock baseClock, Duration tickDuration)
The following example shows how to use tick
.
import java.time.Clock; import java.time.Duration; import java.time.ZoneId; //from ww w. j a v a2 s . c o m public class Main { public static void main(String[] args) { Clock clock = Clock.tickMinutes(ZoneId.systemDefault()); Duration duration = Duration.ofHours(3); Clock newClock = Clock.tick(clock,duration); System.out.println(newClock.instant()); } }
The code above generates the following result.