Java Date Time - Instant now() example








Instant now() gets the current instant from the system clock.

Syntax

now has the following syntax.

public static Instant now()

Example

The following example shows how to use now.

import java.time.Instant;

public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.now();
    System.out.println(instant.getEpochSecond());
    
  }
}

The code above generates the following result.