Here you can find the source of getDurationBreakdown(long millis)
Parameter | Description |
---|---|
millis | A duration to convert to a string form |
public static String getDurationBreakdown(long millis)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { /**/*from w w w . ja v a2 s . c om*/ * Convert a millisecond duration to a string format * * @param millis A duration to convert to a string form * @return A string of the form "X Days Y Hours Z Minutes A Seconds". */ public static String getDurationBreakdown(long millis) { 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); millis -= TimeUnit.MILLISECONDS.toMillis(minutes); StringBuilder sb = new StringBuilder(64); if (days > 0) sb.append(days).append(" days "); if (hours > 0) sb.append(hours).append(" hours "); if (minutes > 0) sb.append(minutes).append(" minutes "); if (seconds > 0) sb.append(seconds).append(" seconds "); if (millis > 0) sb.append(millis).append(" millis"); return sb.toString().trim(); } }