开发者

Joda Period Formatter

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()));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜