I am trying to get the month name of the current date using JavaScript Date (); class. I noticed that there is no way to do this unless I create an array of strings with the names of the months.
var month = new Date();
month.getMonth();
> 10
I want to get "November" instead of an integer. Is there a function called to get the string name in the Date () class, or do I need to create an array such as:
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var d = new Date();
document.write("The current month is " + monthNames[d.getMonth()]);
I know there are libraries for this and the method above, but I am curious to find out if there is a built-in function for this that I am missing.
source
share