I have a requirement for parsing ISO8601 formatted strings in Java with various levels of accuracy. Some examples of the string I need to parse are:
For the first cases with separators (-
, :
) one can use:
DateTimeFormatter dtf = DateTimeFormatter
.ofPattern("uuuu[-MM[-dd[['T']HH[:]mm[[:]ss[[.]SSS]]]]]");
ParsePosition pos = new ParsePosition(0);
TemporalAccessor result = dtf.parse(text, pos);
However neither uuuuMMdd
nor [-]
or ['-']
worked for me in Java 8.