I want to parse strings like "8y5d" or "-6y144d" into a joda time period object. Thanks
Asked
Active
Viewed 1,937 times
1 Answers
11
Use the PeriodFormatterBuilder:
PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendYears()
.appendSuffix("y", "y")
.printZeroRarelyLast()
.appendDays()
.appendSuffix("d", "d")
.toFormatter();
System.out.println(yearsAndMonths.parsePeriod("8y5d").toDurationFrom(new DateTime()).getStandardDays());

Sergiu Dumitriu
- 11,455
- 3
- 39
- 62