Display nanoseconds with Java Date and Time Conversion Character

Java 8Object Oriented ProgrammingProgramming

To display nanoseconds, use the ‘N’ Date and Time conversion specifier.

System.out.printf("Nanoseconds = %tN\n", d);

Example

 Live Demo

import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      Date d = new Date();
      System.out.printf("Nanoseconds = %tN\n", d);
   }
}

Output

Nanoseconds = 092000000
raja
Published on 14-Dec-2018 06:21:51
Advertisements