【发布时间】:2011-03-18 05:48:26
【问题描述】:
我有以下时间段 1month 5d 22h 35m 39s,我想将其格式化为 35d 22h 35m 39s。但是,当使用以下格式化程序时,月份只是被删除并且没有被添加到天数中:
PeriodFormatter formatter = new PeriodFormatterBuilder()
.printZeroAlways()
.appendDays().appendSuffix(" d ")
.appendHours().appendSuffix(" h ")
.appendMinutes().appendSuffix(" m ")
.appendSeconds().appendSuffix(" s ")
.toFormatter();
经过一番搜索,我发现应该在 Period 上使用 normalizedStandard() 方法,但是在将它与 period.normalizedStandard(PeriodType.dayTime()) 一起使用时,我收到以下错误:
java.lang.UnsupportedOperationException: Field is not supported
at org.joda.time.PeriodType.setIndexedField(PeriodType.java:690)
at org.joda.time.Period.withMonths(Period.java:851)
at org.joda.time.Period.normalizedStandard(Period.java:1541)
at amadeus.bid.wicket.markup.html.CountDownLabel.onComponentTagBody(CountDownLabel.java:34)
有什么想法吗?
【问题讨论】:
-
月份和分钟使用相同的后缀。
-
吉尔伯特:很抱歉要删除它。
标签: java formatting jodatime period