#1146·dayjs

Durations: Convert HH:MM:SS string to seconds

Author: hamzahamidiCreated Oct 16, 2020Updated Aug 29, 2026

Describe the bug A clear and concise description of what the bug is. I just wanted to know if it's possible with Dayjs to Convert HH:MM:SS string to seconds. and if it's not possible would you consider implementing this feature? (I'm available for this feature)

The feature can be used like this:

  const duration = dayjs.duration( '02:04:33', 'HH:mm:ss');

and the function would return something like the following:

const d = '02:04:33';   // your input string
const a = hms.split(':'); // split it at the colons

const result = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); 
console.log(result);