开发者

Joda Period Formatter

开发者 https://www.devze.com 2023-04-06 04:48 出处:网络
System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60)));
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

精彩评论

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