Search code examples
javascripttypescriptdatetimeiso8601date-fns

Convert ISO8601 duration to seconds in typescript using date-fns


I have a ISO8601 duration string. ex. "PT1M14S" I want to convert this to seconds (Int) using date-fns package in typescript


Solution

  • One solution is provided by package: iso8601-duration So we could do something like

    import { parse, toSeconds } from 'iso8601-duration';    
    toSeconds(parse("PT1M14S"))
    

    Please let me know date-fns provides any solution for this