Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Human readable time from nanoseconds

Tags:

People also ask

How do you find time in nano seconds?

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.

Is nano second a unit of time?

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.

What is one nano second?

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.

What is System Nano time?

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?