Java
Date & Time API
Master Java 8's modern Date & Time API for handling dates, times, and time zones.
By TechCoder TeamLast updated: 2026-06-02
In a Nutshell
Master Java 8's modern Date & Time API for handling dates, times, and time zones. This hands-on tutorial focuses on practical implementation of date & time api concepts.
Date & Time API (Java 8+)
Java 8 introduced a new Date & Time API (java.time package) to replace the old java.util.Date.
Core Classes
LocalDate
Represents a date without time.
LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1995, 5, 15);
LocalTime
Represents time without date.
LocalTime now = LocalTime.now();
LocalTime lunchTime = LocalTime.of(12, 30);
LocalDateTime
Combines date and time.
LocalDateTime now = LocalDateTime.now();
LocalDateTime meeting = LocalDateTime.of(2024, 1, 15, 14, 30);
ZonedDateTime
Date and time with time zone.
ZonedDateTime zonedNow = ZonedDateTime.now();
ZonedDateTime tokyo = ZonedDateTime.now(ZoneId.of("Asia/Tokyo"));
Period and Duration
Period - Date-based amount (years, months, days) Duration - Time-based amount (hours, minutes, seconds)
Period period = Period.between(LocalDate.of(2020, 1, 1), LocalDate.now());
Duration duration = Duration.between(LocalTime.of(9, 0), LocalTime.now());
Formatting
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
String formatted = now.format(formatter);
AI Mentor
Confused about "Java 8 Date and Time API usage"? Ask our AI mentor for a simplified explanation.
Quiz
Quiz
Question 1 of 3Which class represents date without time?
LocalDate
LocalTime
LocalDateTime