java - jodaTime PeriodFormatter 格式不正确
问题描述
我有这个 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 DAYS、x HOURS、x MINUTES.... 执行此操作时返回一个空字符串。如果我将“appendSeconds()”添加到格式化程序创建中,我会得到与我发送的返回值相同的秒数。
我需要转换,不仅仅是数量,而且我对秒数不感兴趣,而是它占多少分钟,多少小时和多少天..任何可以提供帮助的人?
解决方案
您需要使用Period.normalizedStandard()来说服您的周期将您的秒数转换为分钟、小时和天。
Period(Seconds.seconds(seconds.toInt())).normalizedStandard().toString(it)
(不确定()
Kotlin 中是否需要空圆括号。它们在 Java 中,我在其中进行了测试。)
推荐阅读
- java - 在 Java Springboot 中为 mySQL 自定义生成的具有持久序列的列值
- algorithm - 如何在块算法中显示“if operator in for operator”?
- core-audio - PCM中的音频帧样本类型?
- c# - Kubectl 以交互方式应用 .NET Core 控制台应用程序,并在 Kubernetes 上退出 Console.ReadLine
- javascript - 我无法捕获 Select2 事件 - 我怀疑我使用了错误的 jquery 选择器
- google-chrome - MediaRecorder Chrome 编解码器/容器无法在移动设备或 Safari 上播放
- powershell - Powershell脚本将文件从一个位置移动到另一个位置,然后将消息框显示到我们网络上的另一台计算机
- symfony - 如何修复“key too long”错误并生成 Doctrine 迁移表?
- python - “numpy.ndarray”对象没有属性“fbind”
- css - 使用 Viusal Studio 2019 构建项目时,CSS 文件恢复为未修改版本