Created
April 7, 2023 13:51
-
-
Save DineshSolanki/677e34a9f22715dbf75857bfbd97f907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void showProgressWithETA(int current, int total, long startTime) { | |
long elapsedTimeMillis = System.currentTimeMillis() - startTime; | |
int percent = current * 100 / total; | |
int progress = percent / 2; | |
System.out.print("\r["); | |
for (int i = 0; i < progress; i++) { | |
System.out.print("\u001b[32m=\u001b[0m"); | |
} | |
for (int i = progress; i < 50; i++) { | |
System.out.print(" "); | |
} | |
System.out.printf("] %d%%", percent); | |
if (current > 0) { | |
long remainingTimeMillis = elapsedTimeMillis * (total - current) / current; | |
long remainingTimeSeconds = remainingTimeMillis / 1000; | |
System.out.printf(" (ETA: %d:%02d:%02d)", remainingTimeSeconds / 3600, | |
(remainingTimeSeconds % 3600) / 60, remainingTimeSeconds % 60); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment