How to convert time e.g. 00:31:26 into a number in javascript -


this question has answer here:

i need compare run times of marathon runners, im having difficulty comparing run times in following format; 00:31:26, 00:34:29 (hours:minutes:seconds).

ideally convert whole time minutes use times create graph.

how convert race times number using javascript or otherwise?

this example demonstrates array.split split string components, hours, minutes , seconds held in variable array. uses parseint convert component strings integer, in turn mathematically multiplied , added give representation in seconds.

var time = "01:32:29"; var array = time.split(":"); var seconds = (parseint(array[0], 10) * 60 * 60) + (parseint(array[1], 10) * 60) + parseint(array[2], 10)  console.log(seconds); 

on jsfiddle


Comments