How to convert time to seconds in javascript?

  • 0
    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

  • 2 Answers
  • 0
    const toSeconds = str => str
    .split(':')
    .reverse()
    .reduce((acc, n, i) => acc + n * (60 ** i), 0);
    Jude Wilkerson

  • 0
    ((number_of_days * 24 + number_hours) * 60 + number_minutes) * 60 + number_seconds



    As I understand it, they stopped studying mathematics at school ...
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!