Calculate the remaining download time
I have a code that downloads a file from a URL.
I have two parameters that are calculated for the entire load time:
Long start = System.nanoTime();
// downloading...
Long end = System.nanoTime();
I need to measure the estimated time remaining until the end of the download. How can i do this?
+3
Sergey Shustikov
source
to share
1 answer
It was just, sorry, your time.
For future searchers:
When you start loading the save timestamp:
Long startTime = System.nanoTime();
to calculate the average remaining speed:
Long elapsedTime = System.nanoTime() - startTime;
Long allTimeForDownloading = (elapsedTime * allBytes / downloadedBytes);
Long remainingTime = allTimeForDownloading - elapsedTime;
+5
Sergey Shustikov
source
to share