Display nanoseconds with Java Date and Time Conversion Character


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

System.out.printf("Nanoseconds = %tN
", 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
", d);    } }

Output

Nanoseconds = 092000000

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 27-Jun-2020

599 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements