Format time for hour:minute:second - Android java.util

Android examples for java.util:Date Time

Description

Format time for hour:minute:second

Demo Code

public class Main {

  public static String getTotalVideoTimeFormat(long videoTotalTime) {
    int totalSeconds = (int) (videoTotalTime / 1000L);
    int seconds = totalSeconds % 60;
    int minutes = (totalSeconds / 60) % 60;
    int hours = totalSeconds / 3600;
    return (hours > 0
        ? String.format("%02d:%02d:%02d",
            new Object[] { Integer.valueOf(hours), Integer.valueOf(minutes), Integer.valueOf(seconds) })
        : String.format("%02d:%02d", new Object[] { Integer.valueOf(minutes), Integer.valueOf(seconds) }));
  }//from  w w  w. j  ava 2  s . c o m

}

Related Tutorials