get Time Duration Text - Android java.util

Android examples for java.util:Time

Description

get Time Duration Text

Demo Code


//package com.java2s;

public class Main {
    public static String getDurationText(int duration) {
        int totalSeconds = duration / 1000;
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / (60 * 60);
        String secondsStr = "" + seconds;
        String minutesStr = "" + minutes;
        String hoursStr = "" + hours;

        if (seconds < 10)
            secondsStr = "0" + seconds;
        if (minutes < 10)
            minutesStr = "0" + minutes;
        if (hours < 10)
            hoursStr = "0" + hours;
        String durationString = hoursStr + ":" + minutesStr + ":"
                + secondsStr;/*from   ww  w  . j av  a2  s  .  c  o  m*/

        return durationString;
    }
}

Related Tutorials