java.time.LocalDateTime.now() Method Example



Description

The java.time.LocalDateTime.now() method obtains the current date-time from the system clock in the default time-zone.

Declaration

Following is the declaration for java.time.LocalDateTime.now() method.

public static LocalDateTime now()

Return Value

the current date-time using the system clock and default time-zone, not null.

Example

The following example shows the usage of java.time.LocalDateTime.now() method.

package com.tutorialspoint;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.now();
      System.out.println(date);  
   }
}

Let us compile and run the above program, this will produce the following result −

2017-03-17T15:16:49.524
Advertisements