Handle dates and times correctly with the java.time API

8 steps · about 2 h 15 min · Beginner

  1. Pick the right date-time class (tutorial, Oracle Java Tutorials, 15 min)

    Maps each need to LocalDate, Instant, ZonedDateTime and friends.

  2. Work with dates (tutorial, Oracle Java Tutorials, 20 min)

    LocalDate, DayOfWeek and YearMonth in practice.

  3. Add times with LocalDateTime (tutorial, Oracle Java Tutorials, 15 min)

    Shows date plus time without a zone.

  4. Record moments with Instant (tutorial, Oracle Java Tutorials, 10 min)

    The machine timeline, right for timestamps.

  5. Convert between time zones (tutorial, Oracle Java Tutorials, 25 min)

    Handles ZonedDateTime, offsets and daylight saving.

  6. Measure with Period and Duration (tutorial, Oracle Java Tutorials, 15 min)

    Computes differences between dates and times.

  7. Parse and format with DateTimeFormatter (tutorial, Oracle Java Tutorials, 20 min)

    Turns text into dates and back safely.

  8. Convert from legacy Date and Calendar (tutorial, Oracle Java Tutorials, 15 min)

    Lets you adopt java.time in older code.