Java - ZonedDateTime formatter for ISO-8601

less than 1 minute read

Parse example

1
2
3
4
5
6
7
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
DateTimeFormatter formatter = builder
        .parseCaseInsensitive()
        .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
        .appendOffsetId()
        .toFormatter();
ZonedDateTime.parse("2015-08-18T00:00+01:00", formatter);

toString example

1
2
3
4
5
6
7
8
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
DateTimeFormatter formatter = builder
        .parseCaseInsensitive()
        .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
        .appendOffsetId()
        .toFormatter();
ZonedDateTime zoneTime = new ZonedDatTime();
String date = zoneTime.format(formatter);