Format seconds to time - Android java.util

Android examples for java.util:Date Format

Description

Format seconds to time

Demo Code

import android.util.Log;

public class Main{

    public static String secondToString(int seconds) {
        int min = seconds / 60;
        int second = seconds % 60;

        StringBuffer sb = new StringBuffer();
        if (min > 9) {
            sb.append(String.valueOf(min));
        } else {/*from w ww. j a va2  s  .co m*/
            sb.append("0" + String.valueOf(min));
        }

        if (second > 9) {
            sb.append(":" + String.valueOf(second));
        } else {
            sb.append(":0" + String.valueOf(second));
        }

        return sb.toString();
    }

}

Related Tutorials