DateUtil { public static Date convertToDate(String text, DateFormat format) throws ParseException { SimpleDateFormat dateFormat = format.format; synchronized (dateFormat) { return dateFormat.parse(text); } } private  DateUtil(); static Date convertToDate(String text, DateFormat format); static Date convertToDate(String text); static String now(); static String nowLong(); static String nowMid(); static String nowShort(); static String nowVerbose(); static String nowPlain(); static String convertToString(long millis, DateFormat format); static String convertToString(long millis); static String convertToStringLong(long millis); static String convertToStringMid(long millis); static String convertToStringShort(long millis); static String convertToStringVerbose(long millis); static String convertToStringPlain(long millis); static String convertToStringYearMonth(long millis);  }
@Test public void testConvertToDate() throws Exception { String text = "2012-03-29T12:00:00"; Date date = DateUtil.convertToDate(text); Assert.assertNotNull(date); }
@Test public void testConvertToDateVerbose() throws Exception { String text = "Wed, 21 Mar 2012 02:06:21 UTC"; Date date = DateUtil.convertToDate(text, DateFormat.VERBOSE_FORMAT); Assert.assertNotNull(date); }
@Test public void testConvertToDatePlain() throws Exception { String text = "2012-03-29-12-00-00"; Date date = DateUtil.convertToDate(text, DateFormat.PLAIN_FORMAT); Assert.assertNotNull(date); }