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!

5 thoughts on “javascript get locale month with full name

  1. Hi there, i just read your web site sometimes i personal an equivalent just one we was just thinking driving under the influence a lot of junk e-mail reviews? If that is so how will you avert the item, just about any wordpress plugin and also everything else you can certainly advise? I have a lot recently it can be generating me personally insane hence any there’s help greatly enjoyed.

  2. Maybe I’m just not finding the solution I’m looking for but the frustrating thing about this problem is that your method (which is common) only displays the month names in one language, in this case English. What if the user is speaks another language?

    We can return a string that contains the user’s native language month name with toLocaleDateString() assuming they left their OS at default settings and set their locale settings in their native language. So obviously javascript is able to access and read locale settings but thus far, I have not been able to find a way to make sure I’m just accessing the month name from the locale.

    This leaves the developer to have to manually translate the month name for every language they want to support using yours or similar methods. I’m hoping there’s a better way but I’m fearing the worst right now. 🙁

Leave a Reply

Your email address will not be published. Required fields are marked *