Tuesday, May 15, 2012

Get Month Name In Javascript

Month Name in JavaScript.
Get Month Name Javascript.
Javascript Date Object, Months Names.

There's a very simple way to get the month's name in javascript.  The only problem is, that people do it over and over instead of just placing this in the Date object.

Do, the solution is rather simple:

     Date.prototype.getMonthName = function() {
          var monthNames = [ "January""February""March""April""May""June", 
                        "July""August""September""October""November""December" ];
          return monthNames[this.getMonth()];
     }

Next time you'll want to get a name you can just:
      var month_Name = new Date().getMonthName();

p.s.
Sometime in the near future I'll upload a file with all of my extensions to Javascript's Array and Date objects.

Elad Shalom,
CTO at ITweetLive.com