@Test public void testStringToDateWithFormatWrongDate() throws Exception { String stringDate = "Valor Fake"; Date date = DateUtils.stringToDateWithFormat(stringDate, DateFormatConstants.DATE_FORMAT_TIME); Date expectedDate = new Date(0); assertThat(expectedDate, isDateEqualTo(date)); }
public static Date stringToDateWithFormat(String stringToConvert, String dateFormat) { if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { } } return new Date(0); }
DateUtils { public static Date stringToDateWithFormat(String stringToConvert, String dateFormat) { if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { } } return new Date(0); } }
DateUtils { public static Date stringToDateWithFormat(String stringToConvert, String dateFormat) { if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { } } return new Date(0); } private  DateUtils(); }
DateUtils { public static Date stringToDateWithFormat(String stringToConvert, String dateFormat) { if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { } } return new Date(0); } private  DateUtils(); static Date stringToDateWithFormat(String stringToConvert, String dateFormat); static String dateToStringWithFormat(Date dateToString, String dateFormat); }
DateUtils { public static Date stringToDateWithFormat(String stringToConvert, String dateFormat) { if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { } } return new Date(0); } private  DateUtils(); static Date stringToDateWithFormat(String stringToConvert, String dateFormat); static String dateToStringWithFormat(Date dateToString, String dateFormat);  }