A short and sweet implementation:
// returns date object in 12hr (AM/PM) format
var formatAMPM = function formatAMPM(d) {
var h = d.getHours();
return (h % 12 || 12)
+ ':' + d.getMinutes().toString().padStart(2, '0')
+ ' ' + (h < 12 ? 'A' : 'P') + 'M';
};