get Duration String from duration millisecond in long value - Android java.lang

Android examples for java.lang:String Format

Description

get Duration String from duration millisecond in long value

Demo Code


import java.util.concurrent.TimeUnit;

public class Main {
  public static String getDurationString(long durationMs) {
    return String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(durationMs),
        TimeUnit.MILLISECONDS.toSeconds(durationMs)
            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(durationMs)));
  }/*from w w  w .  ja va 2  s .  c om*/
}

Related Tutorials