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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With