0

I have seen this, but is it possible to use only month and days, not weeks?

For example, instead of "1 month 2 weeks 2 days", I want "1 month 16 days".

mjuarez
  • 16,372
  • 11
  • 56
  • 73
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135

1 Answers1

1

You can use a solution similar to the answer you linked, but you'll also need to use a org.joda.time.PeriodType to normalized the period:

// 1 month, 2 weeks and 2 days
Period p = new Period(0, 1, 2, 2, 0, 0, 0, 0);

PeriodFormatter fmt = new PeriodFormatterBuilder()
    // months
    .appendMonths().appendSuffix(" month", " months").appendSeparator(" and ")
    // days
    .appendDays().appendSuffix(" day", " days")
    .toFormatter();
System.out.println(fmt.print(p.normalizedStandard(PeriodType.yearMonthDayTime())));

This will print:

1 month and 16 days