Posts Tagged ‘Date Formatting’

This snippet extends the date object and provides formatting to short date string. This is usually an issue since JavaScript uses indexes for month. So essentially we create a lookup used for formatting.

// Get the short date dd MMM yyyy
Date.SHORTMONTHNAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
Date.prototype.getShortDateString = function () {
var dateString = this.getDate() + ' ' + Date.SHORTMONTHNAMES[this.getMonth()] + ' ' + this.getFullYear();
return dateString;
};