Period and Date Arithmetic
Add and subtract dates.
Date-Based Amounts
While Duration measures time in hours and seconds, Period measures amounts in years, months, and days. It is the right tool for calendar arithmetic like ages and deadlines.
Adding Days
LocalDate offers plusDays to move forward. Remember the result is a new immutable value.
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate start = LocalDate.of(2026, 5, 30);
System.out.println(start.plusDays(10));
}
}All lessons in this course
- LocalDate, LocalTime, LocalDateTime
- Instant and Duration
- Period and Date Arithmetic
- Formatting with DateTimeFormatter