Convert HH:MM:SS to seconds with JavaScript?

To convert the HH:MM:SS to seconds, you need to multiply the HOUR with 60X60 and Minute with 60:


var time = '10:8:20';
var actualTime = time.split(':');
console.log("The time="+time);
var totalSeconds = (+actualTime[0]) * 60 * 60 + (+actualTime[1]) * 60 + (+actualTime[2]);
console.log("Total Seconds="+totalSeconds);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo61.js.


This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo61.js
The time=10:8:20
Total Seconds=36500