//Get start time and end time
var startTime = moment("12:16:59 am", "HH:mm:ss a"),
endTime = moment("06:12:07 pm", "HH:mm:ss a");
- Method 1
var dif = moment.duration(endTime.diff(startTime));
console.log([dif.hours(), dif.minutes(), dif.seconds()].join(':'));
console.log('dif in Mins: ', (dif.hours() * 60) + dif.minutes());
- Method 2
console.log('hrs: ', moment(endTime).diff(startTime, 'hours'));
console.log('dif in Mins: ', moment(endTime).diff(moment(startTime), 'minutes'));
- Method 3
var hrs = moment.utc(endTime.diff(startTime)).format("HH");
var min = moment.utc(endTime.diff(startTime)).format("mm");
var sec = moment.utc(endTime.diff(startTime)).format("ss");
console.log([hrs, min, sec].join(':'));
- Formatted output
var dif = moment.duration(endTime.diff(startTime));
console.log(dif.humanize());