The Class LocalTime
In this lesson, we will explore a standard class that enables us to get the current time of day at our location.
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 ...