@Test public void testConvertFlexibleDateException() throws ParseException { Assert.assertNull(DateUtil.convertFlexibleDate("")); Assert.assertNull(DateUtil.convertFlexibleDate(null)); try { DateUtil.convertFlexibleDate("unknown"); Assert.fail("Exception not thrown on invalid date.[unknown]"); } catch (ParseException pex) { } }
public static Date convertFlexibleDate(String strDate, String[] formats) throws ParseException { if (StringUtil.isEmpty(strDate)) return null; for (int i=0; i<formats.length; i++) { try { SimpleDateFormat dtFormatter = new SimpleDateFormat(formats[i]); dtFormatter.setLenient(false); return dtFormatter.parse(strDate.trim()); } catch (ParseException e) { } } throw new ParseException("No matching date format for "+strDate, 0); }
DateUtil { public static Date convertFlexibleDate(String strDate, String[] formats) throws ParseException { if (StringUtil.isEmpty(strDate)) return null; for (int i=0; i<formats.length; i++) { try { SimpleDateFormat dtFormatter = new SimpleDateFormat(formats[i]); dtFormatter.setLenient(false); return dtFormatter.parse(strDate.trim()); } catch (ParseException e) { } } throw new ParseException("No matching date format for "+strDate, 0); } }
DateUtil { public static Date convertFlexibleDate(String strDate, String[] formats) throws ParseException { if (StringUtil.isEmpty(strDate)) return null; for (int i=0; i<formats.length; i++) { try { SimpleDateFormat dtFormatter = new SimpleDateFormat(formats[i]); dtFormatter.setLenient(false); return dtFormatter.parse(strDate.trim()); } catch (ParseException e) { } } throw new ParseException("No matching date format for "+strDate, 0); } private  DateUtil(); }
DateUtil { public static Date convertFlexibleDate(String strDate, String[] formats) throws ParseException { if (StringUtil.isEmpty(strDate)) return null; for (int i=0; i<formats.length; i++) { try { SimpleDateFormat dtFormatter = new SimpleDateFormat(formats[i]); dtFormatter.setLenient(false); return dtFormatter.parse(strDate.trim()); } catch (ParseException e) { } } throw new ParseException("No matching date format for "+strDate, 0); } private  DateUtil(); static String dateToString(Date obj, String format); static Date stringToDate(String strDate, String format); static Date convertFlexibleDate(String strDate, String[] formats); static String convertShortDate(Date obj); static Date convertShortDate(String str); static Date convertShortDate(String str, Date defaultDate); static Date convertFlexibleDate(String strDate); static boolean compareNullableDates(Date date1, Date date2); static boolean hasTime(Date date); static Date getClientCurrentDate(final Calendar calendar, final TimeZone timeZone); static Date getDateFrom(int count, Date date); static Date getDayOfTheWeek(int day, int week, int year); static Date removeTime(Date date); }
DateUtil { public static Date convertFlexibleDate(String strDate, String[] formats) throws ParseException { if (StringUtil.isEmpty(strDate)) return null; for (int i=0; i<formats.length; i++) { try { SimpleDateFormat dtFormatter = new SimpleDateFormat(formats[i]); dtFormatter.setLenient(false); return dtFormatter.parse(strDate.trim()); } catch (ParseException e) { } } throw new ParseException("No matching date format for "+strDate, 0); } private  DateUtil(); static String dateToString(Date obj, String format); static Date stringToDate(String strDate, String format); static Date convertFlexibleDate(String strDate, String[] formats); static String convertShortDate(Date obj); static Date convertShortDate(String str); static Date convertShortDate(String str, Date defaultDate); static Date convertFlexibleDate(String strDate); static boolean compareNullableDates(Date date1, Date date2); static boolean hasTime(Date date); static Date getClientCurrentDate(final Calendar calendar, final TimeZone timeZone); static Date getDateFrom(int count, Date date); static Date getDayOfTheWeek(int day, int week, int year); static Date removeTime(Date date);  }