When I use the \"getHour()\" method in javascript, it displays the military time format. I need it to display the hour in numbers between 1-12 instead. Can anybody tell me
Shortest:
const hours12 = date => (date.getHours() % 12 || 12);
If you need padding with 0:
const hours12 = date => ("0"+(date.getHours() % 12 || 12)).slice(-2);
Another option, also with AM & PM:
const hours12 = date => date.toLocaleString('en-US', { hour: 'numeric', hour12: true })