Java: how to use currenttimemillis() to obtain a long time and output it in X decimal places?
•
Java
I have a representative system Long. Of currenttimemillis() Then I'll measure it later in the code I've subtracted two, but now I want to see the time to three decimal places
@H_ 403_ 8@
At present, I use% d to format the output when printing long VaR, and only get non decimal values@ H_ 403_ 8@
Solution
Long is an integer It has no decimal places You mean you want to see seconds to three decimal places?
@H_ 403_ 8@
@H_ 403_ 8@
long start = System.currentTimeMillis(); long time = System.currentTimeMillis() - start; System.out.printf("Took %.3f%n",time/1e3);
You can do the same thing for nanotime, but it's still an integer If you want to view decimal places, you need to divide by 1E3 (microseconds) or 1e6 (milliseconds) or 1e9 (seconds) @ H_ 403_ 8@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码