DateTimes { public static LocalTime tryParseLocalTime(CharSequence text) { if(null == text || text.length() == 0){ return null; } LocalTime t = tryParseLocalTime(text, DateTimeFormatter.ISO_LOCAL_TIME); if(null == t){ t = tryParseLocalTime(text, DateTimeFormatter.ISO_LOCAL_DATE_TIME); if(null == t) { Date d = Dates.tryParse(text.toString(), DateFormats.DATETIME_FORMATTER); if(null != d) { return toLocalTime(d); } } } return t; } protected  DateTimes(); static LocalDate tryParseLocalDate(CharSequence text); static LocalDate tryParseLocalDate(CharSequence text,DateTimeFormatter formatter); static LocalTime tryParseLocalTime(CharSequence text); static LocalTime tryParseLocalTime(CharSequence text,DateTimeFormatter formatter); static LocalDateTime tryParseLocalDateTime(CharSequence text); static LocalDateTime tryParseLocalDateTime(CharSequence text,DateTimeFormatter formatter); static Instant tryParseInstant(CharSequence text); static LocalDate toLocalDate(Date d); static LocalDate toLocalDate(Instant i); static LocalTime toLocalTime(Date d); static LocalTime toLocalTime(Instant i); static LocalDateTime toLocalDateTime(Date d); static LocalDateTime toLocalDateTime(Instant i);  }
@Test public void testParseLocalTimeWithDefaultFormat() { LocalTime t = LocalTime.of(10, 01, 01); assertEquals(t,DateTimes.tryParseLocalTime("10:01:01")); assertEquals(LocalTime.of(10, 01, 00),DateTimes.tryParseLocalTime("10:01")); assertEquals(t,DateTimes.tryParseLocalTime("2014-11-01T10:01:01")); assertEquals(t,DateTimes.tryParseLocalTime("2014-11-01 10:01:01")); }