How can I generate the name of the month (e.g: Oct/October) from this date object in JavaScript?
var objDate = new Date("10/11/2009");
How can I generate the name of the month (e.g: Oct/October) from this date object in JavaScript?
var objDate = new Date("10/11/2009");
It is now possible to do this with the ECMAScript Internationalization API:
long
uses the full name of the month,short
for the short name, andnarrow
for a more minimal version, such as the first letter in alphabetical languages.You can change the locale from
en-us
to any that you please, and it will use the right name for that language/country.With
toLocaleString
you have to pass in the locale and options each time. If you are going do use the same locale info and formatting options on multiple different dates, you can useIntl.DateTimeFormat
instead:The main issue with this API is it is new. It is only available in Blink browsers (Chrome and Opera), IE11, Microsoft Edge, Firefox 29+, and Safari 10+
For more information see my blog post on the Internationalization API.
Here's another one, with support for localization :)
you can then easily add support for other languages:
Some common easy process from date object can be done by this.
Or you can make date prototype like
Ex:
var dateFormat3 = new Date().getMonthName();
# March
var dateFormat4 = new Date().getFormatDate();
# 16 March, 2017
To get a array of month name :
http://jsfiddle.net/polinux/qb346/
Just write a simple wrapper around
toLocaleString
:It can be used as