[英]How to format a time (not a date) using Luxon?
我需要将后端获取的数据“17:00”转换为“5pm”。 使用我只是做的moment
:
moment('17:00', ['HH']).format('h:mma')
如何与Luxon
实现相同的Luxon
? 虽然moment
允许直接格式化时间,但Luxon
的格式化函数似乎需要一个日期(我没有)。
有什么建议吗?
DateTime.fromISO('17:00').toLocaleString(DateTime.TIME_SIMPLE) // 5:00 PM
DateTime.fromISO('17:00').toFormat('h:mma') // 5:00PM
DateTime.fromISO('17:00').toFormat('h:mm a') // 5:00 PM
虽然不知道如何使 meridiem 小写
https://github.com/moment/luxon/issues/224
编辑如果想要小写可以做这样的事情
const dt = DateTime.fromISO('17:00')
const meridiem = (dt.hour > 11) ? 'p' : 'a'
const final = `${dt.toFormat('h:mm')}${meridiem}m`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.