// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class IntervalFormat {
    public static String format(long t) {
        int tmp = (int) (t / 1000);
        String res = (tmp % 60) + "s";
        tmp /= 60;
        if(tmp > 0) {
            res = (tmp % 60) + "m" + res;
            tmp /= 60;
        }
        if(tmp > 0) {
            res = (tmp % 24) + "h" + res;
            tmp /= 24;
        }
        if(tmp > 0) {
            res = tmp + "d" + res;
        }
        return res;
    }
    public static void main(String[] args) {
        long t = (((56 * 24 + 17) * 60 + 23) * 60 + 56) * 1000L + 123;
        System.out.println(format(t));
        System.out.println(format(12345));
    }
}
