Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Forked from akb/gist:1187817
Last active December 2, 2016 20:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gerst20051/7d72693f722bbb0f6b58 to your computer and use it in GitHub Desktop.
Save Gerst20051/7d72693f722bbb0f6b58 to your computer and use it in GitHub Desktop.
Get Current Formatted Date
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