Java 乔达周期格式化程序
上述Joda PeriodFormatter的输出为“1小时30分钟60秒” 我知道这是一个附带案例,但有没有办法将其输出为“1小时31分钟”Java 乔达周期格式化程序,java,jodatime,periodformatter,Java,Jodatime,Periodformatter,上述Joda PeriodFormatter的输出为“1小时30分钟60秒” 我知道这是一个附带案例,但有没有办法将其输出为“1小时31分钟” 谢谢 您可以先使用以下方法对其进行规范化: 或者可能: Period period = Period.hours(1).plusMinutes(30).plusSeconds(60); PeriodFormat.getDefault().print(period.normalizedStandard()); 尝试将添加到标准持续时间(): javado
谢谢 您可以先使用以下方法对其进行规范化: 或者可能:
Period period = Period.hours(1).plusMinutes(30).plusSeconds(60);
PeriodFormat.getDefault().print(period.normalizedStandard());
尝试将
添加到标准持续时间()
:
javadoc for toStandardDuration()说“如果周期包含年或月,将抛出异常”,因此我接受Jon Skeet的回答。谢谢
Period period = Period.hours(1).plusMinutes(30).plusSeconds(60);
PeriodFormat.getDefault().print(period.normalizedStandard());
Period period = Period.hours(1).plusMinutes(30).plusSeconds(60);
PeriodFormat.getDefault()
.print(period.normalizedStandard(period.getPeriodType()));
System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60).toStandardDuration()));