Created
June 7, 2014 10:37
-
-
Save dsaiztc/41f79a2bd534b507bc94 to your computer and use it in GitHub Desktop.
Convert time slot to "00:00:00" format.
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
String convertTime(long start_time, long end_time) | |
{ | |
String result = "00:00:00"; | |
if (end_time > start_time) | |
{ | |
long time = end_time - start_time; | |
long time_hour = TimeUnit.MILLISECONDS.toHours(time); | |
time -= TimeUnit.HOURS.toMillis(time_hour); | |
long time_min = TimeUnit.MILLISECONDS.toMinutes(time); | |
time -= TimeUnit.MINUTES.toMillis(time_min); | |
long time_seg = TimeUnit.MILLISECONDS.toSeconds(time); | |
result = String.format("%02d:%02d:%02d", time_hour, time_min, time_seg); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment