Java Instant get seconds and nano seconds

Description

Java Instant get seconds and nano seconds

import java.time.Instant;

public class Main {
  public static void main(String[] args) {
    // Get the current instant
    Instant i1 = Instant.now();


    // Get seconds and nanoseconds
    long seconds = i1.getEpochSecond();
    int nanoSeconds = i1.getNano();

    System.out.println("Current Instant: " + i1);
    System.out.println("Seconds: " + seconds);
    System.out.println("Nanoseconds: " + nanoSeconds);

  }//w  ww .  jav  a2s .c  o m
}



PreviousNext

Related