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.

- 33,993
- 7
- 53
- 79

- 171
- 1
- 9
-
`ISOPeriodFormat.alternateExtended().parsePeriod("P0000-00-00T12:00:00")` would work but not `ISOPeriodFormat.alternateExtended().parsePeriod("PT12:00:00")`. (tested with Joda-Time 2.1) – Meno Hochschild May 28 '15 at 09:14
2 Answers
"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")

- 7,416
- 1
- 26
- 33
Changing the input to adapt it to the capabilities of the library in use is often not an option. Note that your input is not ISO-compatible because it lacks at least the prefix PT (in alternative ISO-8601-notation). Therefore I suggest following way:
PeriodFormatter pf =
new PeriodFormatterBuilder()
.appendHours().appendLiteral(":")
.appendMinutes().appendLiteral(":")
.appendSeconds().toFormatter();
System.out.println(pf.parsePeriod("12:00:00")); // PT12H
Alternatively I had tested this code:
ISOPeriodFormat.alternateExtended().parsePeriod("P0000-00-00T12:00:00");
This works so far and just requires prefixing the input with the disadvantage that you have to change the input. The shorter prefix PT is ISO-compatible, too, but not supported by Joda-Time (tested in version 2.1).

- 42,708
- 7
- 104
- 126