Skip to content

Instantly share code, notes, and snippets.

@paulanunda
Last active August 29, 2015 13:57
Show Gist options
  • Save paulanunda/9791006 to your computer and use it in GitHub Desktop.
Save paulanunda/9791006 to your computer and use it in GitHub Desktop.
function format_date(date) {
d = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear() + " " + formatAMPM(date);
console.log(date + " : " + d);
return d;
};
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