Date and Time API
java.time provides LocalDate, LocalDateTime, Duration, Period and DateTimeFormatter. Objects are immutable and thread safe.
Example
import java.time.*;
import java.time.format.*;
LocalDate d = LocalDate.of(2026, 3, 15);
System.out.println(d.plusDays(30) + " " + d.getDayOfWeek());
System.out.println(d.format(DateTimeFormatter.ofPattern("dd MMM yyyy")));
System.out.println(Period.between(d, LocalDate.of(2026, 12, 25)).getMonths());
System.out.println(Duration.ofMinutes(135).toHours());Result
2026-04-14 SUNDAY 15 Mar 2026 9 2
Exercise
Add days to a date.
d.(30)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.