-
Notifications
You must be signed in to change notification settings - Fork 4
Getting current date and time with Instant example
Ramesh Fadatare edited this page Jul 11, 2019
·
1 revision
java.time.Instant models a single instantaneous point on the time-line. This might be used to record event time-stamps in the application.
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();