Program
import java.time.LocalDateTime; public class DateTime { public static void main(String[] args) { LocalDateTime current = LocalDateTime.now(); System.out.println("Current Date and Time is: " + current); } }
Output
Current Date and Time is: 2021-04-12T12:22:48.357798800
Description
public static LocalDateTime now()
Obtains the current date-time from the system clock in the default time-zone.
This will query the system clock in the default time-zone to obtain the current date-time.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
Returns:
the current date-time using the system clock and default time-zone, not null