DateFormatUtil { public static String formatDuration(@NotNull Date startDate, @NotNull Date endDate) { return DurationFormatUtils.formatDurationHMS(endDate.getTime() - startDate.getTime()); }  static Date parseDate(@NotNull String pattern, @NotNull String dateString); static String formatDate(@NotNull String pattern, @NotNull Date date); static String formatDate(@NotNull String pattern, long date); static String formatDuration(@NotNull Date startDate, @NotNull Date endDate); static String formatDuration(long durationMillis); static String formatDurationOnSecond(@NotNull Date startDate, @NotNull Date endDate); static String formatDurationOnSecond(long durationMillis); static String formatFriendlyTimeSpanByNow(@NotNull Date date); static String formatFriendlyTimeSpanByNow(long timeStampMillis); static final String PATTERN_ISO; static final String PATTERN_ISO_ON_SECOND; static final String PATTERN_ISO_ON_DATE; static final String PATTERN_DEFAULT; static final String PATTERN_DEFAULT_ON_SECOND; static final FastDateFormat ISO_FORMAT; static final FastDateFormat ISO_ON_SECOND_FORMAT; static final FastDateFormat ISO_ON_DATE_FORMAT; static final FastDateFormat DEFAULT_FORMAT; static final FastDateFormat DEFAULT_ON_SECOND_FORMAT; }
@Test public void formatDuration() { assertThat(DateFormatUtil.formatDuration(100)).isEqualTo("00:00:00.100"); assertThat(DateFormatUtil.formatDuration(new Date(100), new Date(3000))).isEqualTo("00:00:02.900"); assertThat(DateFormatUtil.formatDuration(DateUtil.MILLIS_PER_DAY * 2 + DateUtil.MILLIS_PER_HOUR * 4)) .isEqualTo("52:00:00.000"); assertThat(DateFormatUtil.formatDurationOnSecond(new Date(100), new Date(3000))).isEqualTo("00:00:02"); assertThat(DateFormatUtil.formatDurationOnSecond(2000)).isEqualTo("00:00:02"); assertThat(DateFormatUtil.formatDurationOnSecond(DateUtil.MILLIS_PER_DAY * 2 + DateUtil.MILLIS_PER_HOUR * 4)) .isEqualTo("52:00:00"); }