0

How would i convert a string like this: 1:13:16 Into a number value? It can go up as high as xx:xx:xx

Hours:minutes:seconds

Example list:
duration: 0:37:29
duration: 0:25:57
duration: 1:10:15
duration: 21:2:55

I need to do some false true comparisons so i need to convert them accurately.

Vincent
  • 37
  • 8
  • Take a look at the answers [here](https://stackoverflow.com/questions/9640266/convert-hhmmss-string-to-seconds-only-in-javascript) – PolarisRouge Sep 14 '20 at 19:25

1 Answers1

3

Use split(), like so:

let duration = '0:37:29';
let [hours, minutes, seconds] =
  duration.split(':').map(str => Number.parseInt(str));
Joshua Wade
  • 4,755
  • 2
  • 24
  • 44