@Test public void test_parse_impossible_date_hasrror(){ String formatString = "yyyy-MM-dd HH:mm:ss"; String dateString = "2015-25-22 01:44:50"; assertEquals(null, DateUtil.parse(dateString, formatString)); }
public static Date parse(String dateString, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); Date date = sdf.parse(dateString); return date; } catch (Exception e) { LOGGER.error("error timestamp format,error:{}", e); return null; } }
DateUtil { public static Date parse(String dateString, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); Date date = sdf.parse(dateString); return date; } catch (Exception e) { LOGGER.error("error timestamp format,error:{}", e); return null; } } }
DateUtil { public static Date parse(String dateString, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); Date date = sdf.parse(dateString); return date; } catch (Exception e) { LOGGER.error("error timestamp format,error:{}", e); return null; } } private  DateUtil(); }
DateUtil { public static Date parse(String dateString, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); Date date = sdf.parse(dateString); return date; } catch (Exception e) { LOGGER.error("error timestamp format,error:{}", e); return null; } } private  DateUtil(); static Date parseUTC(String dateString); static boolean validateUTCString(String utcDateString); static String formatUTC(Date date); static Date parse(String dateString, String format); }
DateUtil { public static Date parse(String dateString, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); Date date = sdf.parse(dateString); return date; } catch (Exception e) { LOGGER.error("error timestamp format,error:{}", e); return null; } } private  DateUtil(); static Date parseUTC(String dateString); static boolean validateUTCString(String utcDateString); static String formatUTC(Date date); static Date parse(String dateString, String format);  }