Here you can find the source of formatDuration(long ms)
public static String formatDuration(long ms)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . jav a 2s . c om*/ * NOTE: formatDuration2() recommended in most cases for readability */ public static String formatDuration(long ms) { if (ms < 5 * 1000) { return ms + "ms"; } else if (ms < 3 * 60 * 1000) { return (ms / 1000) + "s"; } else if (ms < 120 * 60 * 1000) { return (ms / (60 * 1000)) + "m"; } else if (ms < 3 * 24 * 60 * 60 * 1000) { return (ms / (60 * 60 * 1000)) + "h"; } else if (ms < 3L * 365 * 24 * 60 * 60 * 1000) { return (ms / (24 * 60 * 60 * 1000)) + "d"; } else if (ms < 1000L * 365 * 24 * 60 * 60 * 1000) { return (ms / (365L * 24 * 60 * 60 * 1000)) + "y"; } else { return "n/a"; } } }