How to get 5 years before now

ZonedDateTime.now().minusYears(5).toInstant()

That will use your default time zone to compute the time. If you want another one, specify it in now(). For example:

ZonedDateTime.now(ZoneOffset.UTC).minusYears(5).toInstant()

According to the Javadoc, Instant will only accept temporal units from nanos to days Instant.plus(long amountToAdd, TemporalUnit unit);

You can use LocalDateTime. You use it the same way, but it will support operation on the YEARS level.


Instant does not support addition or subtraction of YEARS.

You can use this LocalDate if you only need date without time:

LocalDate date = LocalDate.now();
date = date.plus(-5, ChronoUnit.YEARS);

Otherwise you can user LocalDateTime.