DateTimes { public static LocalDate tryParseLocalDate(CharSequence text) { if(null == text || text.length() == 0){ return null; } LocalDate d = tryParseLocalDate(text,DateTimeFormatter.ISO_LOCAL_DATE); if(d == null) { d = tryParseLocalDate(text, DateTimeFormatter.ISO_LOCAL_DATE_TIME); if(d == null) { Date ld = Dates.tryParse(text.toString(),DateFormats.DATETIME_FORMATTER); if(null != ld) { return toLocalDate(ld); } } } return d; } 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 testParseLocalDateWithDefaultFormat() { LocalDate d = LocalDate.of(2014, 11, 01); assertEquals(d,DateTimes.tryParseLocalDate("2014-11-01")); assertEquals(d,DateTimes.tryParseLocalDate("2014-11-01T10:01:01")); assertEquals(d,DateTimes.tryParseLocalDate("2014-11-01 10:01:01")); }