Modern Java APIs · 7 min read · Beginner
Modern Dates with java.time
Work with immutable LocalDate, Instant, and Duration from java.time instead of legacy java.util.Date.
What you'll learn
- Use LocalDate for calendar dates and Instant for UTC timestamps
- Perform immutable date math with .plusDays() and Period.between()
- Format dates cleanly with DateTimeFormatter
Always use the java.time package (LocalDate, LocalDateTime, ZonedDateTime, Instant). Unlike the old mutable java.util.Date, every java.time class is immutable and thread-safe.
Fill-in-the-Blank Exercise
Immutable LocalDate Math
Create a LocalDate and return a new date 7 days later.
var start = LocalDate.(2026, 11, 1);
var due = start.(7);Live Code Lab
JavaTimeDemo.java
Expected OutputClick “Run Live” to compile with OpenJDK 21
Start: 2026-11-01 | Deadline: 2026-11-15 (14 days)
Check Your Understanding
Score: 0 / 1
1. What happens to start when you call start.plusDays(14) on a java.time.LocalDate?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.