HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

Get month name from Date

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
fromnamedatemonthget

Problem

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");

Solution

Shorter version:



const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];

const d = new Date();
document.write("The current month is " + monthNames[d.getMonth()]);




Note (2019-03-08) - This answer by me which I originally wrote in 2009 is outdated. See David Storey's answer for a better solution.

Context

Stack Overflow Q#1643320, score: 1482

Revisions (0)

No revisions yet.