Tag Archives: locale

javascript get locale month with full name

JavaScript Date object

The Date object in JS helps you work with dates as it sounds logical. However there are limited number of functions attached to it which you can use. You can check for full Date specification in w3schools : here.

How to get the month name?

Normally when you try to use a date object you can format it with the following code:

var d = new Date();
alert(d.getFullYear());
alert(d.getMonth());
alert(d.getDate());

The problem is that you cannot reference the date object and to get the full name of the month. Something like d.getFullMonth()!

That’s why the easiest way to get the full month name is to make a custom locale array such this one:

var monthLocale = new Array(12);
monthLocale[0] = "January";
monthLocale[1] = "February";
monthLocale[2] = "March";
monthLocale[3] = "April";
monthLocale[4] = "May";
monthLocale[5] = "June";
monthLocale[6] = "July";
monthLocale[7] = "August";
monthLocale[8] = "September";
monthLocale[9] = "October";
monthLocale[10] = "November";
monthLocale[11] = "December";

And than you can simply reference the locale array!