Android Distance Readable Format durationToHourMinOrMinSec(long duration)

Here you can find the source of durationToHourMinOrMinSec(long duration)

Description

duration To Hour Min Or Min Sec

License

Open Source License

Declaration

public static String durationToHourMinOrMinSec(long duration) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    public static String durationToHourMinOrMinSec(long duration) {
        String time = null;/*from  w  w w.j a v  a  2s.  co m*/
        long hours = TimeUnit.SECONDS.toHours(duration);
        if (hours > 0) {
            long minutes = TimeUnit.SECONDS.toMinutes(duration
                    - TimeUnit.HOURS.toSeconds(hours));
            time = String.format("%02d:%02d", hours, minutes);
        } else {
            long minutes = TimeUnit.SECONDS.toMinutes(duration);
            long seconds = duration - TimeUnit.MINUTES.toSeconds(minutes);
            time = String.format("%02d:%02d", minutes, seconds);
        }
        return time;
    }
}

Related

  1. distance(float distanceInKm, boolean imperial)
  2. distanceToKM(double distance)
  3. distanceToMiles(double distance)