How to convert time to seconds in javascript?
-
I have a string with a time like: 0:02:34. How can I convert it to seconds (154 sec) using javascript?JavaScript Anonymous, Oct 18, 2020
-
const toSeconds = str => str
.split(':')
.reverse()
.reduce((acc, n, i) => acc + n * (60 ** i), 0);Jude Wilkerson -
((number_of_days * 24 + number_hours) * 60 + number_minutes) * 60 + number_seconds
As I understand it, they stopped studying mathematics at school ...Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!