javascript get month name by number code example
Example 1: Javascript get month name
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var d = new Date();
var monthName=months[d.getMonth()];
Example 2: how to write a program that alerts the current month in words in javascript
var currentDate = new Date();
currentDate.toString;
var b = currentDate.toString();
var c = b.slice(4,7);
if (c === "Jan"){
document.write("Current month: January")
}else if(c === "Feb"){
document.write("Current month: February")
}else if(c === "Mar"){
document.write("Current month: March")
}else if(c === "Apr"){
document.write("Current month: April")
}else if(c === "May"){
document.write("Current month: May")
}else if(c === "Jun"){
document.write("Current month: June")
}else if(c === "Jul"){
document.write("Current month: July")
}else if(c === "Aug"){
document.write("Current month: August")
}else if(c === "Sep"){
document.write("Current month: September")
}else if(c === "Oct"){
document.write("Current month: October")
}else if(c === "Nov"){
document.write("Current month: November")
}else if(c === "Dec"){
document.write("Current month: December")
}