Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created June 7, 2014 10:37
Show Gist options
  • Save dsaiztc/41f79a2bd534b507bc94 to your computer and use it in GitHub Desktop.
Save dsaiztc/41f79a2bd534b507bc94 to your computer and use it in GitHub Desktop.
Convert time slot to "00:00:00" format.
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