Q: How to achieve the correct date output in my code? I'm not including the 12:00 PM - 01:00 PM Time
For example:
8:00 AM - 5:00 PM = 8.00

If I input
8:00 AM - 10:00 PM = 2.00

But the correct output is supposed to be (13.00)
Here is my code:
_formatTime = function(amPmString) {
  var d = new Date("03/04/2019 " + amPmString);

  return d.getHours() + ':' + d.getMinutes();
}

_getTimeDifference = function(startTime, endTime) {
  var start = moment.utc(startTime, "HH:mm");
  var end = moment.utc(endTime, "HH:mm");
  var t = (end.isBefore(start)) ? end.add(1, 'day') : '';
  var diff = (end.diff(start)) / 3600000;

  return (t) ? diff - 13 : diff;
};

The correct result that I want is that I have to total the hours of the time-in and time-out and disregard only the lunch break which is 1 hour (12pm-1pm) in the computation of total hours. If the time range that I put is not in the lunch break. It will not deduct 1 hours.

A: Try this:
_getTimeDifference = function(startTime, endTime) {
  var start = moment(startTime, "HH:mm A");
  var end = moment(endTime, "HH:mm A");
  var t = (end.isBefore(start)) ? end : '';
  var diff = (end.diff(start)) / 3600000 -1;

  return (t) ? diff - 13 : diff;
};


A: If your datetime present in Am-Pm format :the TimeSpan class in Datejs might help simplify the problem. It could be exactly your answer, if your problem is just subtract to time in AM-Pm format
I suggest such a code
var date1= Date.parse("6:30 am");
var date2= Date.parse("11:00 pm");

var diff = new TimeSpan(date2- date1);

console.log("Hours: ", diff.hours);
console.log("Minutes: ", diff.minutes);


A: Solution without Moment.js:
// dt1 and dt2 are assumed to be Date() objects:
function hoursDiff( dt1, dt2 ) {
    // Difference in hours:
    var diff = Math.abs(Math.round( (dt2.getTime() - dt1.getTime()) / 1000 / (60 * 60) ) );

    // If range overlaps 12:00 - 1:00 pm, subtract 1 hour:
    if (dt1.getHours() <= 12 && dt2.getHours() >= 13) {
        diff--
    }

    return diff;
}

console.log( hoursDiff( new Date('2020-08-12 8:00:00'), new Date('2020-08-12 17:00:00') ) ) // 8am-5pm = 8
console.log( hoursDiff( new Date('2020-08-12 8:00:00'), new Date('2020-08-12 22:00:00') ) ) // 8am-10pm = 13

This doesn't account for times that begin or end within the 12:00 - 1:00 pm range, just dates that overlap it completely or not at all. It also assumes dates begin and end on hour boundaries, i.e. doesn't account for fractional hours.
