Java LocalDateTime now() Method
Example
Display the current date and time:
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime myObj = LocalDateTime.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 date and time, read from the system clock (the clock of the computer that runs the program).
When you print it, the letter T separates the date from the time, for example 2026-11-06T14:30:15.123456. Use the format() method to show it in another format.
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 LocalDateTime now()
public static LocalDateTime now(ZoneId zone)
public static LocalDateTime 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 date and time, as a LocalDateTime object. |
|---|
Related Pages
❮ Date and Time Methods