Difference between times
by LyndseyB
JavaScript
var line = "14:01:57 12:47:11";
var spl = line.split(' '),
time1 = convert(spl[0]),
time2 = convert(spl[1]),
ms = time2-time1;
console.log(output(ms));
function convert(n) {
var x = n.split(':'),
dateObj = new Date('', '', '', x[0], x[1], x[2], '');
return dateObj;
}
function leading(n) {
return (n<10) ? '0'+n : n;
}
function output(n) {
var seconds = leading(parseInt((n/1000)%60)),
minutes = leading(parseInt((n/(1000*60))%60)),
hours = leading(parseInt((n/(1000*60*60))%24));
return hours + ':' + minutes + ':' + seconds;
}