JavaScript Short Date Formatter

Posted: November 26, 2010 in Quick Tips
Tags: ,

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;
};
Advertisements
Comments
  1. jim says:

    What is this mumbo jumbo? I want to know about skateboartin! Cmon slappy pick it up

  2. urHelper says:

    visit http://codebeautify.org/

    it is one of the good online editor+beautifier+minifier+validator for javascript,json,xml,html,css……

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s