How to convert a value from nanoseconds to seconds?
Here\'s the code segment:
import java.io.*;
import java.util.concurrent.*;
..
class Stamper
To reduce verbosity, you can use a static import:
import static java.util.concurrent.TimeUnit.NANOSECONDS;
-and henceforth just type
NANOSECONDS.toSeconds(elapsedTime);
Well, you could just divide by 1,000,000,000:
long elapsedTime = end - start;
double seconds = (double)elapsedTime / 1_000_000_000.0;
If you use TimeUnit
to convert, you'll get your result as a long, so you'll lose decimal precision but maintain whole number precision.