Hot to get month name from Date inJavascript?

+1 vote
316 views
asked May 6, 2018 by Hitesh Garg (352 points)  

How get the name of the month from a date object in Javascript (e.g: Jan)?

var objDate = new Date();

1 Answer

+1 vote
answered May 7, 2018 by Rahul Singh (543 points)  
selected Jan 28 by Hitesh Garg
 
Best answer

I can give two simple solutions

let monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
let date = new Date();
console.log(date.getDate() + " " + (monthNames[date.getMonth()]) + "," + date.getFullYear());

And the other one is

let date = new Date();
console.log(date.getDate() + " " + (date.toLocaleString("en-us", { month: "short" })) + ", " + date.getFullYear());
Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...