Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Farmatique/64cf13e9a1474dc1b75a9058833659fd to your computer and use it in GitHub Desktop.
Save Farmatique/64cf13e9a1474dc1b75a9058833659fd to your computer and use it in GitHub Desktop.
Date Am/Pm format
//from here: https://stackoverflow.com/a/8888498/6775194
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment