I have two times, let say:
t1= \'05:34:01\' ;
t2= \'20:44:44\' ;
I want two evaluate difference between these two times in same format. Li
I would also go with the moment.js
but you could do:
function time_diff(t1, t2) {
var parts = t1.split(':');
var d1 = new Date(0, 0, 0, parts[0], parts[1], parts[2]);
parts = t2.split(':');
var d2 = new Date(new Date(0, 0, 0, parts[0], parts[1], parts[2]) - d1);
// this would also work
// d2.toTimeString().substr(0, d2.toTimeString().indexOf(' '));
return (d2.getHours() + ':' + d2.getMinutes() + ':' + d2.getSeconds());
}