DateFormatUtil { public static String formatDate(@NotNull String pattern, @NotNull Date date) { return FastDateFormat.getInstance(pattern).format(date); }  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 formatWithPattern() { Date date = new Date(116, 10, 1, 12, 23, 44); assertThat(DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT, date)) .isEqualTo("2016-11-01 12:23:44.000"); assertThat(DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT, date.getTime())) .isEqualTo("2016-11-01 12:23:44.000"); }