Skip to content

Latest commit

 

History

History
68 lines (40 loc) · 3.17 KB

File metadata and controls

68 lines (40 loc) · 3.17 KB

Unit 12 — Mastering Java Date and Time API

Free forever · Browser-based · No setup required Back to course


Overview

This unit equips students with the skills to handle date and time operations efficiently in Java. They will learn to work with legacy date classes, navigate modern Java 8+ time APIs, manage time zones, and format date-time values effectively.

By the end of this unit, students will be able to implement precise and flexible date-handling features in their applications.


Learning Flow

Each lesson in this unit follows the same structure:

  • Read the concept
  • Study the example
  • Write or modify Java code
  • Compile the program
  • Run the code
  • Review the output
  • Complete a hands-on lab
  • Answer review questions

Topics Covered

Working with the util.Date class

The java.util.Date class is the original Java class for representing a specific moment in time. Students will learn to create Date objects, retrieve the current date and time, and understand the limitations of the legacy Date class, including its mutability and the fact that many of its methods have been deprecated in favor of newer APIs.

Navigating Java's Calendar and TimeZone classes

The Calendar class provides methods for manipulating dates, such as adding or subtracting days, months, and years. The TimeZone class allows programs to work with dates and times in different time zones. Students will practice performing date arithmetic using Calendar and converting between time zones using TimeZone.

Understanding the Java 8 Date and Time API

Java 8 introduced a new date and time API in the java.time package that addresses the problems of the legacy classes. The new API is immutable and thread-safe. LocalDate represents a date without a time. LocalTime represents a time without a date. LocalDateTime represents both a date and a time. Students will practice creating, comparing, and manipulating instances of each class.

Exploring advanced Date and Time API features

Students will work with ZonedDateTime to represent a date and time with time zone information, Period to represent a date-based amount of time such as years and months, Duration to represent a time-based amount of time such as hours and seconds, and Instant to represent a specific point on the timeline. These classes cover the full range of date and time scenarios in professional Java applications.

Formatting date and time using DateTimeFormatter

The DateTimeFormatter class converts date and time objects to formatted strings and parses date and time strings back into objects. Students will practice formatting dates using predefined formats as well as custom patterns, and parsing date strings from various formats commonly found in data files and APIs.


Recommended Academic Levels

This unit is introduced at College / University — Year 3.

Academic Level Track
College / University — Year 3 Units 1–13

Start this unit Terms of Use · Privacy Policy

© Java Pro Academy. All rights reserved.