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. Like the result of above must come as
t3= t2 - t1; // 15:10:43
What is the way to do it?
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. Like the result of above must come as
t3= t2 - t1; // 15:10:43
What is the way to do it?
I would also go with the
moment.js
but you could do:I also used
momentjs
but withduration
and got correct different between times:try this
Highly recommend you include moment.js in your project if you need to handle time.
Example:
Working jsFiddle
To install moment.js in Node.js, simply do:
npm install moment
(or for a global installsudo npm -g install moment
)And then in your Node.js, include it like so:
Edit: For 24h clock, change
hh
toHH
.