DateUtil { public static int toSeconds(String hh_colon_mm) { Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.| AM| PM|AM|PM|)"); Matcher m = p.matcher(hh_colon_mm); int retval = 0; if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; if ((m.group(3).equals(" a.m.") || m.group(3).equals(" AM") || m.group(3).equals("AM")) && m.group(1).equals("12")) retval -= 12 * 60 * 60; if ((m.group(3).equals(" p.m.") || m.group(3).equals(" PM") || m.group(3).equals("PM")) && !(m.group(1).equals("12"))) retval += 12 * 60 * 60; } return retval; }  static Date fromISODateString(String isoDateString); static String toISOString(Date date, String format, TimeZone tz); static String toISOString(Date date); static String toISOString(long date); static String toISOAsUTC(final long timestamp); static String toISONoZone(final long timestamp); static Date toDate(Integer seconds); static int toSeconds(String hh_colon_mm); static String dateString(Date date); static String dateString(long mills); static String dateStringShort(long mills); static String timeString(Date date); static String timeString(long mills); static String timeStringWithSeconds(long mills); static String timeFullString(long mills); static String dateAndTimeString(Date date); static String dateAndTimeRangeString(long start, long end); static String dateAndTimeString(long mills); static String dateAndTimeAndSecondsString(long mills); static String dateAndTimeFullString(long mills); static String minAgo(long time); static String minAgoShort(long time); static String hourAgo(long time); static String timeStringFromSeconds(int seconds); static String timeFrameString(long timeInMillis); static String sinceString(long timestamp); static String untilString(long timestamp); static long now(); static long roundDateToSec(long date); static boolean isCloseToNow(long date); static boolean isOlderThan(long date, long minutes); static GregorianCalendar gregorianCalendar(); static long getTimeZoneOffsetMs(); static int getTimeZoneOffsetMinutes(final long timestamp); static String niceTimeScalar(long t); static String qs(double x, int digits);  }
@Test public void toSecondsTest() { Assert.assertEquals(3600, DateUtil.toSeconds("01:00")); Assert.assertEquals(3600, DateUtil.toSeconds("01:00 a.m.")); Assert.assertEquals(3600, DateUtil.toSeconds("01:00 AM")); }