Minus duration in Java local datetime from now example

1 · Adrian Matei · July 6, 2021, 10:06 a.m.
Get current day with LocalDateTime.now() from which you can substract years, weeks, days up to nanos (in the shown example days with minusDays(long days)): LocalDateTime dateToLookBack = LocalDateTime.now().minusDays(30); You can achieve the same result by using the minus(TemporalAmount amountToSubtract) method as below final var dateToLookBackTo = LocalDateTime.now().minus(Duration.ofDays(30)); Reference - https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html ...