@Test public void testLongToTimePeriod() { assertEquals("2.99s", Utils.longToTimePeriod(3000 - 12)); assertEquals("1d21h", Utils.longToTimePeriod(45L * 3600 * 1000)); }
public static String longToTimePeriod(long msec) { if (msec < 1000) return msec + "ms"; if (msec < 3000) return String.format("%.2fs", msec / 1000d); if (msec < 60 * 1000) return (msec / 1000) + "s"; long sec = msec / 1000; if (sec < 5 * 60) return (sec / 60) + "m" + (sec % 60) + "s"; long min = sec / 60; if (min < 60) return min + "m"; long hour = min / 60; if (min < 24 * 60) return hour + "h" + (min % 60) + "m"; long day = hour / 24; return day + "d" + (hour % 24) + "h"; }
Utils { public static String longToTimePeriod(long msec) { if (msec < 1000) return msec + "ms"; if (msec < 3000) return String.format("%.2fs", msec / 1000d); if (msec < 60 * 1000) return (msec / 1000) + "s"; long sec = msec / 1000; if (sec < 5 * 60) return (sec / 60) + "m" + (sec % 60) + "s"; long min = sec / 60; if (min < 60) return min + "m"; long hour = min / 60; if (min < 24 * 60) return hour + "h" + (min % 60) + "m"; long day = hour / 24; return day + "d" + (hour % 24) + "h"; } }
Utils { public static String longToTimePeriod(long msec) { if (msec < 1000) return msec + "ms"; if (msec < 3000) return String.format("%.2fs", msec / 1000d); if (msec < 60 * 1000) return (msec / 1000) + "s"; long sec = msec / 1000; if (sec < 5 * 60) return (sec / 60) + "m" + (sec % 60) + "s"; long min = sec / 60; if (min < 60) return min + "m"; long hour = min / 60; if (min < 24 * 60) return hour + "h" + (min % 60) + "m"; long day = hour / 24; return day + "d" + (hour % 24) + "h"; }  }
Utils { public static String longToTimePeriod(long msec) { if (msec < 1000) return msec + "ms"; if (msec < 3000) return String.format("%.2fs", msec / 1000d); if (msec < 60 * 1000) return (msec / 1000) + "s"; long sec = msec / 1000; if (sec < 5 * 60) return (sec / 60) + "m" + (sec % 60) + "s"; long min = sec / 60; if (min < 60) return min + "m"; long hour = min / 60; if (min < 24 * 60) return hour + "h" + (min % 60) + "m"; long day = hour / 24; return day + "d" + (hour % 24) + "h"; }  static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String longToTimePeriod(long msec); static ImageIcon getImageIcon(String resource); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static String getNodeIdShort(String nodeId); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static List<ByteArrayWrapper> dumpKeys(DbSource<byte[]> ds); static DataWord allButOne64th(DataWord dw); static void showErrorAndExit(String message, String... messages); static void showWarn(String message, String... messages); static String sizeToStr(long size); static void sleep(long ms); static boolean isHexEncoded(String value); }
Utils { public static String longToTimePeriod(long msec) { if (msec < 1000) return msec + "ms"; if (msec < 3000) return String.format("%.2fs", msec / 1000d); if (msec < 60 * 1000) return (msec / 1000) + "s"; long sec = msec / 1000; if (sec < 5 * 60) return (sec / 60) + "m" + (sec % 60) + "s"; long min = sec / 60; if (min < 60) return min + "m"; long hour = min / 60; if (min < 24 * 60) return hour + "h" + (min % 60) + "m"; long day = hour / 24; return day + "d" + (hour % 24) + "h"; }  static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String longToTimePeriod(long msec); static ImageIcon getImageIcon(String resource); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static String getNodeIdShort(String nodeId); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static List<ByteArrayWrapper> dumpKeys(DbSource<byte[]> ds); static DataWord allButOne64th(DataWord dw); static void showErrorAndExit(String message, String... messages); static void showWarn(String message, String... messages); static String sizeToStr(long size); static void sleep(long ms); static boolean isHexEncoded(String value); static double JAVA_VERSION; }