Java Date Time - Instant now(Clock clock) example








Instant now(Clock clock) gets the current instant from the specified clock.

Syntax

now has the following syntax.

public static Instant now(Clock clock)

Example

The following example shows how to use now.

import java.time.Clock;
import java.time.Instant;
/*from   ww w  . j  av  a 2s  .c om*/
public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.now(Clock.systemDefaultZone());
    System.out.println(instant.getEpochSecond());
    
  }
}

The code above generates the following result.