I don't usually like writing code for people, but I'm feeling nice today.
function parse12hToMin(timeStr){ //returns the minutes as an offset from 12:00 AM
let match12h = new RegExp(
"^" + // start of string
"(1[0-2]|[1-9])" + // hour
":" + // separator
"([0-5][0-9])" + // minutes
" " + // separator
"(am|pm)" // AM or PM
, 'i'); // case insensitive
let matched = timeStr.match(match12h);
let min = parseInt(matched[1]) * 60 // hours
+ parseInt(matched[2]) // minutes
+ (matched[3].toLowerCase() === "pm" ? 720 : 0); // 720 min PM offset
return min;
}
function minutesDiff12h(start, end){
return parse12hToMin(end) - parse12hToMin(start);
}
console.assert(minutesDiff12h("10:00 am","3:30 pm") === 330);
Please always try to list what you tried, and show us the code snippets that aren't working.