UTCDateUtil { public String formatUTCDate(final Date sourceDate) { return formatDate(sourceDate, DATE_FORMAT_UTC); }  Date parseUTCDateOptionalTimeZone(final String dateString); String formatUTCDate(final Date sourceDate); String formatUTCDateOnly(final Date sourceDate); Date parseDate(final String dateString, final String dateFormat, final TimeZone timeZone); static final String DATE_ONLY_FORMAT; static final String DATE_FORMAT_UTC; static final String DATE_FORMAT_FULL; }
@Test public void testFormatUTCDateAM() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); Date sourceDate = createUTCDate(1984, 3, 5, 2, 5, 59); String expectedFormatStr = "19840305020559"; String resultFormatStr = utcDateUtil.formatUTCDate(sourceDate); assertNotNull("Format string was null", resultFormatStr); assertEquals("Format date not as expected", expectedFormatStr, resultFormatStr); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }
@Test public void testFormatUTCDatePM() { try { UTCDateUtil utcDateUtil = new UTCDateUtil(); Date sourceDate = createUTCDate(1984, 3, 5, 21, 5, 59); String expectedFormatStr = "19840305210559"; String resultFormatStr = utcDateUtil.formatUTCDate(sourceDate); assertNotNull("Format string was null", resultFormatStr); assertEquals("Format date not as expected", expectedFormatStr, resultFormatStr); } catch (Throwable t) { t.printStackTrace(); fail(t.getMessage()); } }