我试图使用使用Duration.fromMillis().toFormat()的卢克松来转换持续时间(以秒为单位)。
我想要它输出1d2h一天两小时,但我无法逃脱d和h。
以下是我迄今所尝试的
Duration.fromMillis(3600 * 26 * 1000).toFormat('d\dh\h')
Duration.fromMillis(3600 * 26 * 1000).toFormat('d[d]h[h]') // Like MomentJS两者都不起作用
发布于 2022-05-06 08:25:26
正如其他人在评论中已经指出的,您可以使用单引号来转义鲁迅中的charcters,请参阅文档的逃逸部分:
您可以使用单引号转义字符串: DateTime.now().toFormat("HH‘小时和’mm‘分钟“);// '20小时55分钟’
下面是一个工作示例:
const Duration = luxon.Duration;
console.log(Duration.fromMillis(3600 * 26 * 1000).toFormat("d'd'h'h'"));<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>
https://stackoverflow.com/questions/72128831
复制相似问题