UNPKG

hhmmsstosec

Version:

Converts hhmmss time format to seconds

16 lines (15 loc) 570 B
function hhmmssToSec(time) { if (!time.match(/[0-9]+:[0-9]+/)) return 'Invalid Time' let thing = time.replace(':', ' ').replace(':', ' '); let args = thing.split(/ +/); if (args.length == 2) { let hours = parseInt(args[0]) / 60 + parseInt(args[1]) / 3600 let seconds = hours * 3600 return seconds } else if (args.length == 3) { let hours = parseInt(args[0]) + parseInt(args[1]) / 60 + parseInt(args[2]) / 3600 let seconds = hours * 3600 return seconds } } module.exports = hhmmssToSec;