Here you can find the source of getDurationBreakdown(long millis)
Parameter | Description |
---|---|
millis | a parameter |
public static String getDurationBreakdown(long millis)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { /**/* w ww. jav a2s . c om*/ * @param millis * @return String */ public static String getDurationBreakdown(long millis) { long time = millis; if (time < 0) { throw new IllegalArgumentException("Duration must be greater than zero!"); } long days = TimeUnit.MILLISECONDS.toDays(time); time -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(time); time -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(time); time -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(time); StringBuilder sb = new StringBuilder(64); if (days > 0) { sb.append(days); sb.append("d"); } if (hours > 0) { sb.append(hours); sb.append("h"); } if (minutes > 0) { sb.append(minutes); sb.append("m"); } if (seconds > 0) { sb.append(seconds); sb.append("s"); } return (sb.toString()); } }