Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Milliseconds and nanoseconds in time format

Tags:

java

This is my code:

long currentTime = System.currentTimeMillis();
Date date = new Date(currentTime); // if you really have long
String result = new SimpleDateFormat("HH:mm:ss").format(date.getTime());

Is it possible to add milliseconds and nanoseconds to the date format ?

like image 654
user1735757 Avatar asked Nov 30 '22 22:11

user1735757


1 Answers

You can add milliseconds by adding SSS at the end, such as the format will be HH:mm:ss.SSS.

There is no reference in the SimpleDateFormat to nanoseconds. Usually System.nanoTime() is used for performance debugging and not for display purposes.

like image 87
Dan D. Avatar answered Dec 09 '22 16:12

Dan D.