Java LocalTime now() Method
Example
Display the current time:
import java.time.LocalTime;
public class Main {
public static void main(String[] args) {
LocalTime myObj = LocalTime.now();
System.out.println(myObj);
}
}
Note: The output is different each time you run the program.
Definition and Usage
The now() method returns the current time, read from the system clock (the clock of the computer that runs the program).
When you print the time, it is shown as hours, minutes, seconds and parts of a second, for example 14:30:15.123456.
Note: The example shows the time of the server that runs it, which may be different from your local time.
Syntax
One of the following:
public static LocalTime now()
public static LocalTime now(ZoneId zone)
public static LocalTime now(Clock clock)
Parameter Values
| Parameter | Description |
|---|---|
| zone | Optional. The time zone (the local time of a region) to use, for example ZoneId.of("UTC"). If it is left out, the default time zone of the computer is used. |
| clock | Optional. The clock to read from. It is mostly used to test programs with a fixed date and time. |
Technical Details
| Returns: | The current time, as a LocalTime object. |
|---|
Related Pages
❮ Date and Time Methods