Getting current date and time with Instant example

java.time.Instant models a single instantaneous point on the time-line. This might be used to record event time-stamps in the application.

Getting current date and time with Instant example

The code example uses java.time.Instant to get the current date and time.
import java.time.Instant;

public class JavaCurrentDateInstant {

    public static void main(String[] args) {
        
        Instant instant = Instant.now();
        System.out.println(instant);
    }
}
Output:
2019-07-11T17:26:19.881Z
The Instant.now() method obtains the current instant from the system clock:
Instant instant = Instant.now();



Comments