The hour that doesn't exist
java.time (Java 8) replaced the old, error-prone Date and Calendar with clear immutable types: LocalDate and LocalDateTime for calendar values, Instant for a moment on the timeline, ZonedDateTime for a moment in a particular time zone, and Duration/Period for amounts of time.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Print how many days are left until 31 December 2026 from 5 October 2026.
Given a flight that departs Mumbai on 2026-11-20 at 23:15 local time and lasts 9 hours 40 minutes, print the arrival time in London.
Print the dates of every Monday in November 2026.
Explain it without notes
When do you use LocalDate, LocalDateTime, Instant and ZonedDateTime?
What is the difference between Duration and Period?
Why was java.util.Date replaced, and why is java.time safer?
Expected output
2026-03-08T03:30-04:00[America/New_York]
hours in that day: 23