-
-
Save Gerst20051/7d72693f722bbb0f6b58 to your computer and use it in GitHub Desktop.
Get Current Formatted Date
This file contains 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 getMonthStrings() { | |
return [ | |
'January', | |
'February', | |
'March', | |
'April', | |
'May', | |
'June', | |
'July', | |
'August', | |
'September', | |
'October', | |
'November', | |
'December' | |
]; | |
} | |
function getCurrentFormattedDate(date) { | |
return (function () { | |
return getMonthStrings()[this.getMonth()] + ' ' + (function (d) { | |
var s = d.toString(), l = s[s.length - 1]; | |
return s + (['st', 'nd', 'rd'][l - 1] || 'th'); | |
})(this.getDate()) + ', ' + this.getFullYear() + ' ' + ('0' + (this.getHours() % 12 || 12)).slice(-2) + ':' + ('0' + this.getMinutes()).slice(-2) + ':' + ('0' + this.getSeconds()).slice(-2) + ' ' + (this.getHours() >= 12 ? 'PM' : 'AM'); | |
}).call(date || new Date()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment