public static String formatMillis(long millis) { StringBuilder sb = new StringBuilder(); formatMillis(sb, "", millis); return sb.toString(); }
public static String formatMillis(long millis) { StringBuilder sb = new StringBuilder(); formatMillis(sb, "", millis); return sb.toString(); }
@Override public String asChars() { try { StringBuilder sb = new StringBuilder(); String prefix = ""; if (months != 0) { int positiveNum = Math.abs(months); int year = positiveNum / 12; int remainMonth = positiveNum - year * 12; if (year > 0) { sb.append(months < 0 ? "-" : ""); sb.append(year).append(year == 1 ? " year" : " years"); prefix = " "; } sb.append(prefix).append(months < 0 ? "-" : "").append(remainMonth).append(months == 1 ? " month" : " months"); prefix = " "; } formatMillis(sb, prefix, milliseconds); return sb.toString(); } catch (Exception e) { return ""; } }
@Override public String asChars() { try { StringBuilder sb = new StringBuilder(); String prefix = ""; if (months != 0) { int positiveNum = Math.abs(months); int year = positiveNum / 12; int remainMonth = positiveNum - year * 12; if (year > 0) { sb.append(months < 0 ? "-" : ""); sb.append(year).append(year == 1 ? " year" : " years"); prefix = " "; } sb.append(prefix).append(months < 0 ? "-" : "").append(remainMonth).append(months == 1 ? " month" : " months"); prefix = " "; } formatMillis(sb, prefix, milliseconds); return sb.toString(); } catch (Exception e) { return ""; } }