System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60)));
The output from the above Joda PeriodFormatter is "1 hour, 30 minutes and 60 seconds".
I know that this is a fri开发者_运维百科nge case, but is there a way to output this as "1 hour and 31 minutes"?
Thanks!
You could normalize it first with normalizedStandard
:
Period period = Period.hours(1).plusMinutes(30).plusSeconds(60);
PeriodFormat.getDefault().print(period.normalizedStandard());
Or possibly:
Period period = Period.hours(1).plusMinutes(30).plusSeconds(60);
PeriodFormat.getDefault()
.print(period.normalizedStandard(period.getPeriodType()));
Try adding toStandardDuration()
:
System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60).toStandardDuration()));
精彩评论