Skip to content Skip to sidebar Skip to footer

Get The Time Difference Between Two Times In Format Hh:mm:ss

I have two times in HH:mm:ss format. I am trying to calculate the time difference between two times. like var timeStart = '01:00:24'; var timeEnd = '01:00:34' var timeDiff =

Solution 1:

You can split them with : and take difference. And again join them with :

var start = '01:00:24';
var end = '01:00:34';
var diff = start.split(':').map((item,index) => end.split(':')[index] - item).join(':')
console.log(diff)

Solution 2:

you can prepone to both a fixed date and do the subtraction:

var start='01:00:24';
var end='01:00:34';
start='2017-11-8'+start;
end='2017-11-8'+end;
var diff =+end-+start; // outputs 10000 (in ms)

Post a Comment for "Get The Time Difference Between Two Times In Format Hh:mm:ss"