Here you can find the source of formatDuration(long time)
public static String formatDuration(long time)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { public static String formatDuration(long time) { long millis = time; long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); StringBuilder b = new StringBuilder(); if (days > 0) b.append(days).append(" Days, "); if (hours > 0) b.append(hours).append(" Hours, "); if (minutes > 0) b.append(minutes).append(" Minutes, "); return b.append(seconds).append(" Seconds").toString(); }/*from w w w. j av a2 s. c o m*/ }