9

我想将像“8y5d”或“-6y144d”这样的字符串解析成一个joda时间段对象。谢谢

4

1 回答 1

11

使用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());
于 2012-08-30T21:16:09.230 回答