Last active
August 29, 2015 13:57
-
-
Save paulanunda/9791006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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