how to convert time to am pm in javascript

JavaScript
var suffix = hour >= 12 ? "PM":"AM";
var hours = ((hour + 11) % 12 + 1) + suffix
Source

Also in JavaScript: