Search code examples
javajodatimeperiodformatter

ISOPeriodFormat.standard().parsePeriod("12:00:00") Exception


I try to call the parsePeriod() with the parameter "12:00:00", and it runs an IllegalArgumentException. I try the decompile the PeriodFormatter class, and getParser().parseInto(localMutablePeriod, paramString, 0, iLocale); this line turns wrong. Can anybody tells me the reason? Thanks.


Solution

  • "12:00:00" is not the correct ISO 8601 duration format. See the description of the format here: http://en.wikipedia.org/wiki/ISO_8601#Durations

    In your case, if you mean a 12-hour duration, the parameter should be "PT12H0M0S": ISOPeriodFormat.standard().parsePeriod("PT12H0M0S")