Here you can find the source of durationToHourMinOrMinSec(long duration)
public static String durationToHourMinOrMinSec(long duration)
//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; } }