@Test public void testFormatTime() { assertTrue("00:01:40".equals(DateUtils.formatTime(100))); assertTrue("00:01:00".equals(DateUtils.formatTime(60))); assertTrue("00:00:00".equals(DateUtils.formatTime(0))); assertTrue("00:00:00".equals(DateUtils.formatTime(-1))); assertTrue("100:00:00".equals(DateUtils.formatTime(360000))); }
public static String formatTime(long seconds) { if (seconds <= 0) { return "00:00:00"; } int second = (int) (seconds % SECOND_PER_MINUTE); seconds = seconds / SECOND_PER_MINUTE; int minute = (int) (seconds % MINUTE_PER_HOUR); seconds = seconds / MINUTE_PER_HOUR; long hour = seconds; StringBuilder sb = new StringBuilder(StringUtils.asciiSizeInBytes(hour) + 6); sb.append(hour < 10 ? "0" : "").append(hour).append(":"); sb.append(minute < 10 ? "0" : "").append(minute).append(":"); sb.append(second < 10 ? "0" : "").append(second); return sb.toString(); }
DateUtils { public static String formatTime(long seconds) { if (seconds <= 0) { return "00:00:00"; } int second = (int) (seconds % SECOND_PER_MINUTE); seconds = seconds / SECOND_PER_MINUTE; int minute = (int) (seconds % MINUTE_PER_HOUR); seconds = seconds / MINUTE_PER_HOUR; long hour = seconds; StringBuilder sb = new StringBuilder(StringUtils.asciiSizeInBytes(hour) + 6); sb.append(hour < 10 ? "0" : "").append(hour).append(":"); sb.append(minute < 10 ? "0" : "").append(minute).append(":"); sb.append(second < 10 ? "0" : "").append(second); return sb.toString(); } }
DateUtils { public static String formatTime(long seconds) { if (seconds <= 0) { return "00:00:00"; } int second = (int) (seconds % SECOND_PER_MINUTE); seconds = seconds / SECOND_PER_MINUTE; int minute = (int) (seconds % MINUTE_PER_HOUR); seconds = seconds / MINUTE_PER_HOUR; long hour = seconds; StringBuilder sb = new StringBuilder(StringUtils.asciiSizeInBytes(hour) + 6); sb.append(hour < 10 ? "0" : "").append(hour).append(":"); sb.append(minute < 10 ? "0" : "").append(minute).append(":"); sb.append(second < 10 ? "0" : "").append(second); return sb.toString(); }  }
DateUtils { public static String formatTime(long seconds) { if (seconds <= 0) { return "00:00:00"; } int second = (int) (seconds % SECOND_PER_MINUTE); seconds = seconds / SECOND_PER_MINUTE; int minute = (int) (seconds % MINUTE_PER_HOUR); seconds = seconds / MINUTE_PER_HOUR; long hour = seconds; StringBuilder sb = new StringBuilder(StringUtils.asciiSizeInBytes(hour) + 6); sb.append(hour < 10 ? "0" : "").append(hour).append(":"); sb.append(minute < 10 ? "0" : "").append(minute).append(":"); sb.append(second < 10 ? "0" : "").append(second); return sb.toString(); }  static boolean isSameDay(final Date date1, final Date date2); static boolean isSameDay(final Calendar cal1, final Calendar cal2); static boolean isSameWeek(final Date date1, final Date date2); static boolean isSameWeek(Calendar cal1, Calendar cal2); static boolean isSameMonth(final Date date1, final Date date2); static boolean isSameMonth(Calendar cal1, Calendar cal2); static Date addYears(final Date date, final int amount); static Date addMonths(final Date date, final int amount); static Date addWeeks(final Date date, final int amount); static Date addDays(final Date date, final int amount); static Date addHours(final Date date, final int amount); static Date addMinutes(final Date date, final int amount); static Date addSeconds(final Date date, final int amount); static Date addMilliseconds(final Date date, final int amount); static long toSeconds(Date date); static long toSeconds(long milliseconds); static long toSecondsByStartOfDay(LocalDate localDate); static long toDays(Date date); static long toDays(long milliseconds); static long diffSeconds(Date date1, Date date2); static long diffDays(Date date1, Date date2); static String formatTime(long seconds); }
DateUtils { public static String formatTime(long seconds) { if (seconds <= 0) { return "00:00:00"; } int second = (int) (seconds % SECOND_PER_MINUTE); seconds = seconds / SECOND_PER_MINUTE; int minute = (int) (seconds % MINUTE_PER_HOUR); seconds = seconds / MINUTE_PER_HOUR; long hour = seconds; StringBuilder sb = new StringBuilder(StringUtils.asciiSizeInBytes(hour) + 6); sb.append(hour < 10 ? "0" : "").append(hour).append(":"); sb.append(minute < 10 ? "0" : "").append(minute).append(":"); sb.append(second < 10 ? "0" : "").append(second); return sb.toString(); }  static boolean isSameDay(final Date date1, final Date date2); static boolean isSameDay(final Calendar cal1, final Calendar cal2); static boolean isSameWeek(final Date date1, final Date date2); static boolean isSameWeek(Calendar cal1, Calendar cal2); static boolean isSameMonth(final Date date1, final Date date2); static boolean isSameMonth(Calendar cal1, Calendar cal2); static Date addYears(final Date date, final int amount); static Date addMonths(final Date date, final int amount); static Date addWeeks(final Date date, final int amount); static Date addDays(final Date date, final int amount); static Date addHours(final Date date, final int amount); static Date addMinutes(final Date date, final int amount); static Date addSeconds(final Date date, final int amount); static Date addMilliseconds(final Date date, final int amount); static long toSeconds(Date date); static long toSeconds(long milliseconds); static long toSecondsByStartOfDay(LocalDate localDate); static long toDays(Date date); static long toDays(long milliseconds); static long diffSeconds(Date date1, Date date2); static long diffDays(Date date1, Date date2); static String formatTime(long seconds); static final int MILLISECOND_PER_SECOND; static final int SECOND_PER_MINUTE; static final int MINUTE_PER_HOUR; static final int HOUR_PER_DAY; }