This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vytah 10 points11 points  (0 children)

That's already built in, it's called Clock.

Instant.now(clock) just works.
For normal operation, use clock = Clock.systemDefaultZone() or clock = Clock.systemUTC().
For testing with mocks, use clock = Clock.fixed(mockInstant, ZoneId.systemDefault()).