Hot to get month name from Date inJavascript?

+1 vote
43 views
asked May 6 by Hitesh Garg (346 points)  

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

var objDate = new Date();

1 Answer

0 votes
answered May 7 by Rahul Singh (518 points)  

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.
...