Durations: Convert HH:MM:SS string to seconds
See original GitHub issueDescribe 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);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Convert HH:MM:SS to seconds - Online tools
This tool converts human readable time using hours/minutes/seconds to seconds. You might also like the online Convert seconds to HH:MM:SS tool.
Read more >Convert HH:MM:SS string to seconds only in javascript
== 60 seconds... so.. Only solution I think of is to split the string in array and then multiply 3600 to hour and...
Read more >Convert HH:MM:SS to Seconds using JavaScript | bobbyhadz
To convert `hh:mm:ss` to seconds, convert the hours to seconds, by multiplying by `60` twice. Convert the minutes to seconds by multiplying by...
Read more >Converting hh:mm:ss into seconds - MATLAB Answers
I want to convert Time column ( HH:MM:SS) to min, there is a direct command time2num but it requires toolbox and it's paid.So...
Read more >Converting seconds to time string & time ... - write - Corbpie
Converting seconds to a time string and time string to seconds with vanilla Javascript. The time string is in the format of hh:mm:ss...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve done the following
The
.map()
is used to convert each split token to an integer.I would use a feature, like this. I develop for a video and audio production environment. Taking human formatted duration inputs and changing them to seconds, for calculation, is a very common task. I find durations most useful when summing (i.e. getting total duration of video clips to see if they will fit on a DVD). Using @hamzahamidi example, it would be helpful to have flexibility in the input format (“HH:mm” or “mm:ss”).
Additional duration methods like average, max value, min value, etc, might also be useful.