Moment js subtract 2 times

Hello everybody i want to subtract 2 times from each other like i have time in this second in variable called _start _start :any=moment().format('LTS'); // 4:01:15 and i have the time after 5 seconds in variable called _end

 _end = moment().format('LTS'); // 4:01:20

then i want the difference between them which is 0:00:05 how can i do that in moment.js i already used _end.diff(_start, "seconds") i got an error says that _end.diff is not a function.thank u if u don't understand me please check toggl.com i want to make a task like this website.

Upvotes: 1

Views: 833

Answers (1)

jemiloii
jemiloii

Reputation: 25719

You should format the final date. Otherwise you'll need to reparse.

 _start = moment();
 //later
 _end = moment();

 moment(_end.diff(_start)).format('H:mm:ss'); // 4:01:15
 moment(_end.diff(_start)).format('H:mm:ss A'); // 4:01:15 PM

Upvotes: 2

Related Questions