我有一个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()“添加到格式化程序创建中,就会得到与我发送的返回值相同的秒数。
我需要转换,而不仅仅是数量,我不感兴趣的是秒数,而是它占了多少分钟、几小时和几天。有人能帮忙吗?
发布于 2018-05-27 10:33:49
你需要使用Period.normalizedStandard()来说服你的经期将你的秒转换为分钟、小时和天。
Period(Seconds.seconds(seconds.toInt())).normalizedStandard().toString(it)(不确定Kotlin中是否需要空圆括号()。它们在Java中,我在那里进行了测试。)
https://stackoverflow.com/questions/50550548
复制相似问题