Java Data Type How to - Get value from Instant








Question

We would like to know how to get value from Instant.

Answer

import java.time.Instant;
/*from   w  ww  .ja v a 2  s .co  m*/
public class Main {

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

The code above generates the following result.