nanoTime() method returns the current value of the most precise available system timer, in nanoseconds. The value returned represents nanoseconds since some fixed but arbitrary time (in the future, so values may be negative) and provides nanosecond precision, but not necessarily nanosecond accuracy.
A nanosecond (ns) is a unit of time in the International System of Units (SI) equal to one billionth of a second, that is, 1⁄1 000 000 000 of a second, or 10−9 seconds.
A nanosecond (ns or nsec) is one billionth (10-9) of a second and is a common measurement of read or write access time to random access memory (RAM). Admiral Grace Hopper famously handed out foot-long lengths of wire to students to illustrate how far an electrical signal can travel in a nanosecond.
nanoTime() Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.
I am trying to implement an ETA feature Using System.nanoTime()
startTime = System.nanoTime()
Long elapsedTime = System.nanoTime() - startTime;
Long allTimeForDownloading = (elapsedTime * allBytes / downloadedBytes);
Long remainingTime = allTimeForDownloading - elapsedTime;
But I cannot figure how to get a human readable form of the nanoseconds; for example: 1d 1h
, 36s
and 3m 50s
.
How can I do this?
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