Search code examples
javascriptecmascript-6date-fns

Format Time Date-FNS


I have a time that I want to convert to a regular time like 08:00:01 PM.

data.time = "18:54:00"

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

Solution

  • You need to parse it before formatting, and your format string is wrong. Check the parse docs

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