DateUtil { public static String formatYearMonthDayNoDash(Date date) { return formatYearMonthDayNoDash(new LocalDate(date)); } private  DateUtil(); static String formatYearMonthDayNoDash(Date date); static String formatYearMonthDayNoDash(LocalDate date); static String formatYearMonthDay(Date date); static String formatYearMonthDay(LocalDate date); static String formatYearMonth(Date date); static String formatYearMonth(LocalDate date); static String formatYearMonthNoDash(Date date); static String formatYearMonthNoDash(LocalDate date); static LocalDate parseLocalDate(String timestamp); static String lastMonthInYearMonthFormat(); static LocalDate firstDayPreviousMonth(); static LocalDate lastDayPreviousMonth(); static LocalDate firstDayMonth(LocalDate localDate); static LocalDate lastDayMonth(LocalDate localDate);  }
@Test public void testYearMonthDayNoDash() { calendar.set(2011, Calendar.SEPTEMBER, 15, 0, 0); int offset = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()) - localCalendar.getTimeZone().getOffset(calendar.getTimeInMillis()); Date date = new Date(calendar.getTimeInMillis() + offset); String formatted = DateUtil.formatYearMonthDayNoDash(date); assertEquals( "Error formatting yyyyMMdd for " + calendar.getTimeZone().getID(), "20110915", formatted); calendar.set(2013, Calendar.JULY, 1, 0, 0); offset = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()) - localCalendar.getTimeZone().getOffset(calendar.getTimeInMillis()); date.setTime(calendar.getTimeInMillis() + offset); formatted = DateUtil.formatYearMonthDayNoDash(date); assertEquals( "Error formatting yyyyMMdd for " + calendar.getTimeZone().getID(), "20130701", formatted); LocalDate localDate = new LocalDate(2011, 9, 15); formatted = DateUtil.formatYearMonthDayNoDash(localDate); assertEquals( "Error formatting yyyyMMdd for " + calendar.getTimeZone().getID(), "20110915", formatted); localDate = new LocalDate(2013, 1, 31); formatted = DateUtil.formatYearMonthDayNoDash(localDate); assertEquals( "Error formatting yyyyMMdd for " + calendar.getTimeZone().getID(), "20130131", formatted); }