Java Instant now() method

The now() method of Java Instant class is used to obtain the current instant from the system clock.

The Java Instant now() method consists of 2 parameters:

  • Java Instant now() method
  • Java Instant now(Clock clock) method

The Instant now() method will query the system UTC clock to obtain the current instant.

The Instant now(Clock clock) method will query the specified now to obtain the current time.

Syntax

Parameters

clock - the clock to use, not null.

Return

The current instant, not null.

The current instant using the system clock, not null.

Java Instant now() method Example

Example 1

Output:

The output will be like this.

1410134852

Example 2

Output:

The output will be like this.

2017-05-01T20:57:32.709Z

Java Instant now(Clock clock) method Example

Example 3

Output:

The output will be like this.

2017-03-15T09:18:34.062Z

Example 4

Output:

The output will be like this.

2017-05-01T20:57:34.818Z