【发布时间】:2022-11-10 22:08:42
【问题描述】:
我正在尝试将 Int / TimeInterval 格式化为 String 并具有以下所需输出:
Int(3600 + 600) formats to -> "1 h 10 m"
我尝试使用DateComponentsFormatter,它有一些预定义的格式,其中最接近的是.abbreviated,导致"1h 10m",但是在单位和它的值之间没有空格。
我还尝试使用新的.formattedRange 运算符,如下所示:.formatted(.components(style: .condensedAbbreviated, fields: [.hour, .minute])),这也导致"1h 10m",没有任何添加空格的选项。
最后我尝试使用Measurement<UnitDuration> 的.formatted 属性,但没有成功。
尝试使用DateIntervalFormatter 也无济于事。但是这种格式似乎并不适合手头的任务。
那么怎么办呢?
【问题讨论】:
标签: swift formatting date-formatting nscalendar nsdatecomponents