@Test public void testParse() { for (Entry<String, String> input : ACTUAL_TO_EXPECTED.entrySet()) { ZonedDateTime zdt = parseISODateTime(input.getKey()); ZonedDateTime expected = parseISODateTime(input.getValue()); assertEquals(DateUtils.formatISODateTime(zdt), input.getValue()); assertEquals(zdt.toInstant().toEpochMilli(), expected.toInstant().toEpochMilli()); } }
public static ZonedDateTime parse(String string, DateTimeFormatter... formatters) { if (string.length() > 10 && string.charAt(10) == ' ') { char[] s = string.toCharArray(); s[10] = 'T'; string = new String(s); } for (DateTimeFormatter formatter : formatters) { try { TemporalAccessor ta = formatter.parseBest(string, ZonedDateTime::from, LocalDate::from); if (ta instanceof ZonedDateTime) { return (ZonedDateTime) ta; } else { return ((LocalDate) ta).atStartOfDay(ZoneOffset.UTC); } } catch (Exception e) { } } throw new DateTimeException("Could not parse '" + string + "'"); }
DateUtils { public static ZonedDateTime parse(String string, DateTimeFormatter... formatters) { if (string.length() > 10 && string.charAt(10) == ' ') { char[] s = string.toCharArray(); s[10] = 'T'; string = new String(s); } for (DateTimeFormatter formatter : formatters) { try { TemporalAccessor ta = formatter.parseBest(string, ZonedDateTime::from, LocalDate::from); if (ta instanceof ZonedDateTime) { return (ZonedDateTime) ta; } else { return ((LocalDate) ta).atStartOfDay(ZoneOffset.UTC); } } catch (Exception e) { } } throw new DateTimeException("Could not parse '" + string + "'"); } }
DateUtils { public static ZonedDateTime parse(String string, DateTimeFormatter... formatters) { if (string.length() > 10 && string.charAt(10) == ' ') { char[] s = string.toCharArray(); s[10] = 'T'; string = new String(s); } for (DateTimeFormatter formatter : formatters) { try { TemporalAccessor ta = formatter.parseBest(string, ZonedDateTime::from, LocalDate::from); if (ta instanceof ZonedDateTime) { return (ZonedDateTime) ta; } else { return ((LocalDate) ta).atStartOfDay(ZoneOffset.UTC); } } catch (Exception e) { } } throw new DateTimeException("Could not parse '" + string + "'"); } private  DateUtils(); }
DateUtils { public static ZonedDateTime parse(String string, DateTimeFormatter... formatters) { if (string.length() > 10 && string.charAt(10) == ' ') { char[] s = string.toCharArray(); s[10] = 'T'; string = new String(s); } for (DateTimeFormatter formatter : formatters) { try { TemporalAccessor ta = formatter.parseBest(string, ZonedDateTime::from, LocalDate::from); if (ta instanceof ZonedDateTime) { return (ZonedDateTime) ta; } else { return ((LocalDate) ta).atStartOfDay(ZoneOffset.UTC); } } catch (Exception e) { } } throw new DateTimeException("Could not parse '" + string + "'"); } private  DateUtils(); static String formatISODateTime(Calendar calendar); static String formatISODateTime(Date date); static String formatISODateTime(ZonedDateTime zdt); static String formatISODateTime(ZonedDateTime zdt, boolean dateOnly); static Date nowIfNull(Date date); static Calendar nowIfNull(Calendar calendar); static ZonedDateTime nowIfNull(ZonedDateTime zdt); static ZonedDateTime parseISODateTime(String string); static ZonedDateTime parse(String string, DateTimeFormatter... formatters); static final DateTimeFormatter robustOfPattern(String pattern); static Calendar toCalendar(Instant instant); static Date toDate(ZonedDateTime zdt); static Instant toInstant(Calendar calendar); static ZonedDateTime toZonedDateTime(Calendar calendar); static ZonedDateTime toZonedDateTime(Date date); }
DateUtils { public static ZonedDateTime parse(String string, DateTimeFormatter... formatters) { if (string.length() > 10 && string.charAt(10) == ' ') { char[] s = string.toCharArray(); s[10] = 'T'; string = new String(s); } for (DateTimeFormatter formatter : formatters) { try { TemporalAccessor ta = formatter.parseBest(string, ZonedDateTime::from, LocalDate::from); if (ta instanceof ZonedDateTime) { return (ZonedDateTime) ta; } else { return ((LocalDate) ta).atStartOfDay(ZoneOffset.UTC); } } catch (Exception e) { } } throw new DateTimeException("Could not parse '" + string + "'"); } private  DateUtils(); static String formatISODateTime(Calendar calendar); static String formatISODateTime(Date date); static String formatISODateTime(ZonedDateTime zdt); static String formatISODateTime(ZonedDateTime zdt, boolean dateOnly); static Date nowIfNull(Date date); static Calendar nowIfNull(Calendar calendar); static ZonedDateTime nowIfNull(ZonedDateTime zdt); static ZonedDateTime parseISODateTime(String string); static ZonedDateTime parse(String string, DateTimeFormatter... formatters); static final DateTimeFormatter robustOfPattern(String pattern); static Calendar toCalendar(Instant instant); static Date toDate(ZonedDateTime zdt); static Instant toInstant(Calendar calendar); static ZonedDateTime toZonedDateTime(Calendar calendar); static ZonedDateTime toZonedDateTime(Date date); static final String ISODATETIME_GENERIC_PATTERN; static final DateTimeFormatter ISO_ROBUST_DATE_TIME; static final DateTimeFormatter[] formatters; static final DateTimeFormatter ISO_DATE_ONLY; }