How do you display a JavaScript datetime object in the 12 hour format (AM/PM)?
In modern browsers, use Intl.DateTimeFormat
and force 12hr format with options:
let now = new Date();
new Intl.DateTimeFormat('default',
{
hour12: true,
hour: 'numeric',
minute: 'numeric'
}).format(now);
// 6:30 AM
Using default
will honor browser's default locale if you add more options, yet will still output 12hr format.