The Class LocalTime
Explore the Java LocalTime class from the java.time package to understand how to create time objects, retrieve time components, and compare times. Learn import practices and key methods like now, getHour, equals, compareTo, isBefore, and isAfter.
The Java Class Library contains the package java.time, which contains classes related to dates and times. Among them is the class LocalTime. An object in this class represents the actual time of day that it was created. The time is recorded in 24-hour notation to the nearest nanosecond as hh:mm:ss.ddddddddd.
The import statement
As we saw in an earlier lesson, Simple Input from a Keyboard, if our program uses a class from a package, we write an import statement that appears before the rest of our program. To import the class LocalTime from the package java.time, we write
import java.time.LocalTime;
If we use more than one class in a package, we can import the entire package by writing an asterisk instead of a class name, as in
import java.time.*;
While importing an entire package is common among some programmers, we will import each class ...