Search code examples
javascriptmomentjsdayjs

DayJS formatting with duration plugin returns undefined when passing day, hour and minute


Using momentjs, it works perfectly fine - returning 13m:

moment.duration(sg.time_played, 'seconds').format('d[d] h[h] m[m]')

And with DayJS:

dayjs.duration(sg.time_played, 'seconds').format('d[d] h[h] m[m]')

It would return the following string: undefinedd undefined 13m.

The expected output from both functions is 13m and wasn't entirely sure why the DayJS plugin wasn't working like moment's.

Thanks.


Solution

  • Use H and D instead h and d like that:

    dayjs.duration(seconds, 'seconds').format('D[d] H[h] m[m]')