Here you can find the source of millisToString(long ms)
public static final String millisToString(long ms)
//package com.java2s; //License from project: LGPL import java.util.concurrent.TimeUnit; public class Main { public static final String millisToString(long ms) { if (ms <= 0) { throw new IllegalArgumentException("Input must be greater than zero"); }/* ww w . ja va 2s .c om*/ long hours = TimeUnit.MILLISECONDS.toHours(ms); ms -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(ms); ms -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(ms); StringBuilder sb = new StringBuilder(); if (hours > 0) { sb.append(hours + "h"); } if (minutes > 0) { sb.append(minutes + "m"); } if (seconds > 0) { sb.append(seconds + "s"); } return sb.toString(); } }