I want to parse strings like "8y5d" or "-6y144d" into a joda time period object. Thanks
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With