Custom Adjusters
Description
You can use the ofDateAdjuster() method to create your own date adjuster for a LocalDate.
Example
The following code creates a date adjuster.
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
//w ww. j av a 2s. c o m
public class Main {
public static void main(String[] args) {
// Create an adjuster that retruns a date after 3 months and 2 days
TemporalAdjuster adjuster = TemporalAdjusters
.ofDateAdjuster((LocalDate date) -> date.plusMonths(3).plusDays(2));
LocalDate today = LocalDate.now();
LocalDate dayAfter3Mon2Day = today.with(adjuster);
System.out.println("Today: " + today);
System.out.println("After 3 months and 2 days: " + dayAfter3Mon2Day);
}
}
The code above generates the following result.