我需要将后端获取的数据"17:00“转换为”5 5pm“。使用moment我只需要做:
moment('17:00', ['HH']).format('h:mma')如何用Luxon实现同样的功能呢?虽然moment允许直接格式化时间,但Luxon的format functions似乎需要日期(我没有)。
有什么建议吗?
发布于 2021-10-27 12:46:54
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我想不出怎么把子午线写成小写
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`https://stackoverflow.com/questions/69738300
复制相似问题