Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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