Dates And Times
The java.time API models dates and times with immutable types. Choose a type based on what the value means:
| Type | Represents |
|---|---|
LocalDate | A calendar date without a time or zone |
LocalTime | A time of day without a date or zone |
LocalDateTime | A date and time without a zone |
Instant | A moment on the global timeline |
ZonedDateTime | A date and time in a named time zone |
ISO text such as 2026-07-20 parses directly. plusDays returns a new value instead of changing the original date, and plusWeeks, plusMonths, and plusYears work the same way at their own scale.
Move a date forward
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate start = LocalDate.parse("2026-07-20");
LocalDate review = start.plusDays(10);
LocalDate retro = start.plusWeeks(3);
System.out.println(review);
System.out.println(review.getDayOfWeek());
System.out.println(retro);
System.out.println(start);
}
}
Output:
2026-07-30
THURSDAY
2026-08-10
2026-07-20
Adding ten days produces a new review date, and getDayOfWeek derives its weekday. plusWeeks(3) moves 21 days ahead. The last line shows that start itself never changed.
LocalDate alone cannot identify an instant because it has neither a time of day nor a time zone.
Parse the launch date, add the supplied weeks, and print the arrival date and its weekday.