@Test public void test_parse_noerror(){ String formatString = "yyyy-MM-dd HH:mm:ss"; String dateString = "2015-01-22 01:44:50"; Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 2015); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 22); c.set(Calendar.HOUR_OF_DAY, 01); c.set(Calendar.MINUTE, 44); c.set(Calendar.SECOND, 50); c.set(Calendar.MILLISECOND, 0); Date date = new Date(c.getTimeInMillis()); assertEquals(date.compareTo(DateUtil.parse(dateString, formatString)), 0); }
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);  }