Date and Time API Questions
40 min · Intermediate
The java.time package (Java 8) is the modern date and time API: immutable, thread-safe classes with clear names such as LocalDate and Instant. Interviewers ask why it replaced Date and Calendar, which class to use when, and small coding questions like age from a birth date. Section 8, Date & Time API, taught it in full; this lesson is the revision.
Topics in this lesson
- Why java.time replaced Date and Calendar
- LocalDate, LocalDateTime, ZonedDateTime, Instant: when to use each
- Period vs Duration, and DateTimeFormatter
- Coding questions: age from birth date, days between dates
- Traps: immutability, months starting at 1, month-end and invalid dates
Interview questions this lesson answers
- What is the java.time package?
- Why was java.time introduced when Date and Calendar existed?
- Is java.util.Date deprecated?
- What is the difference between LocalDate, LocalTime and LocalDateTime?
- What is the difference between LocalDateTime and ZonedDateTime?
- What is an Instant, and when would you use it?
- How should a backend store date-times?
- What is the difference between ZoneId and ZoneOffset?
- What is the difference between Period and Duration?
- How do you find the number of days between two dates?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.