get Duration String from duration milliseconds - Android java.util.concurrent

Android examples for java.util.concurrent:TimeUnit

Description

get Duration String from duration milliseconds

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  ww  w  .  j a  va2s  .  c  o  m*/

}

Related Tutorials