DateUtils { public static Date convertToDate(String date) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(ALLOWED_DATE_FORMAT); return sdf.parse(date); }  static String convertToReadableTime(Long timestamp); static Long convertToTimestamp(String time, String format); static Date convertToDate(String date); static String convertDateToString(Date date); static Long getDateDifferenceInMinutes(Date oldTime); static boolean isFutureTime(Date time); static Date getDateSpecifiedTimeAgo(String periodString); static final String ALLOWED_DATE_FORMAT; }
@Test public void testConvertToDate() throws Exception { String time = "2013-11-18T14:29:29-0000"; Date date = DateUtils.convertToDate(time); Assert.assertNotNull(date); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(Calendar.YEAR, 2013); calendar.set(Calendar.MONTH, Calendar.NOVEMBER); calendar.set(Calendar.DAY_OF_MONTH, 18); calendar.set(Calendar.HOUR_OF_DAY, 14); calendar.set(Calendar.MINUTE, 29); calendar.set(Calendar.SECOND, 29); calendar.set(Calendar.MILLISECOND, 0); Assert.assertEquals(0, date.compareTo(calendar.getTime())); }