time in am pm format in js code example
Example 1: js get time in am
var time = new Date();
console.log(
time.toLocaleString('en-US', { hour: 'numeric', hour12: true })
);
Example 2: js date remove am and pm
var ampm = hours >= 12 ? 'pm' : 'am';