格式时间日期-FNS

Format Time Date-FNS

我有一个时间想转换为常规时间,例如 08:00:01 下午。

data.time = "18:54:00"

format(new Date(data.time), `hh:mm:ss A`)

格式化前需要解析,你的格式化字符串是错误的。检查 parse docs

format(parse('18:54:00', 'HH:mm:ss', new Date), 'hh:mm:ss a')

// > 06:54:00 PM