Here you can find the source of millisToTimeDelta(long millis)
public static String millisToTimeDelta(long millis)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { public static String millisToTimeDelta(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.SECONDS.toMillis(seconds); String out = ""; if (days > 0) { out += days + "d "; }//ww w.j a v a 2 s . c o m if (hours > 0) { out += hours + "h "; } if (minutes > 0) { out += minutes + "m "; } if (seconds > 0) { out += seconds + "s "; } if (millis > 0) { out += millis + "ms"; } return out.trim(); } }