get String Representation For time Duration - Android java.util

Android examples for java.util:Time

Description

get String Representation For time Duration

Demo Code


//package com.java2s;

public class Main {
    private static final int HOURS_TO_SECONDS = 3600;
    private static final int MINUTES_TO_SECONDS = 60;

    public static String getStringRepresentationFor(int duration) {
        int h = duration / HOURS_TO_SECONDS;
        int m = (duration - (h * HOURS_TO_SECONDS)) / MINUTES_TO_SECONDS;
        int s = (duration - (h * HOURS_TO_SECONDS)) % MINUTES_TO_SECONDS;
        return String.format("%02d:%02d:%02d hh:mm:ss", h, m, s);
    }//from  w w  w .ja v a 2s.  c  om
}

Related Tutorials