gpt4 book ai didi

java - jodaTime periodFormatter 格式不正确

转载 作者:行者123 更新时间:2023-12-02 11:12:00 26 4
gpt4 key购买 nike

我有这个PeriodFormatter:

PeriodFormatterBuilder()
.appendDays()
.appendSuffix(
" day",
" days")
)
.appendSeparator(", ")
.printZeroRarelyLast()
.appendHours()
.appendSuffix(
" hours",
" hours"
)
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(" minute")
.toFormatter()
.let {
Period(Seconds.seconds(seconds.toInt())).toString(it)
}

我想以秒为输入并得到 x 天,x 小时,x 分钟回来......执行此操作时我得到一个空字符串。如果我将“appendSeconds()”添加到格式化程序创建中,我会得到与我发送的返回值相同的秒数。

我需要转换,而不仅仅是金额,而且我对秒数不感兴趣,而是对它占多少分钟、小时和天感兴趣。有人可以提供帮助吗?

最佳答案

您需要使用Period.normalizedStandard()说服您的经期将秒转换为分钟、小时和天。

            Period(Seconds.seconds(seconds.toInt())).normalizedStandard().toString(it)

(不确定 Kotlin 中是否需要空圆括号 ()。它们在 Java 中,我在其中进行了测试。)

关于java - jodaTime periodFormatter 格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50550548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com