Issue
@Spy
Clock clock = Clock.fixed(Instant.parse(
"2021-08-28T08:00:42.00Z"), ZoneId.of("Europe/Kiev"));
Time set as needed, but the date is static. I want it to be today for testing ( or be absent at all ). How can this be done?
P.S. The day the code is executed the date must always reflect the current day but the time must always be 11 pm
Solution
private static final ZoneId ZONE = ZoneId.of("Europe/Kiev");
private static final LocalDate TODAY = LocalDate.now(ZONE);
private static final LocalTime TIME = LocalTime.of(23, 0); // 11 PM
private static final Instant fixedInstant
= TODAY.atTime(TIME).atZone(ZONE).toInstant();
Clock clock = Clock.fixed(fixedInstant, ZONE);
We can try it out:
System.out.println(ZonedDateTime.now(clock));
Output:
2021-08-29T23:00+03:00[Europe/Kiev]
Answered By - Ole V.V.