var today_date = new Date();
// Using toLocaleString(Ecmascript)
// Full month name
const full_month_name = today_date.toLocaleString('default', { month: 'long' });
console.log(full_month_name);
// -> October(Or the current month)
//Short month name
const short_month_name = today_date.toLocaleString('default', { month: 'short' });
console.log(short_month_name);
// -> Oct (Or the short version of current month)
//Using getMonth() method
const month_num = today_date.getMonth();
const all_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const current_month = all_months[month_num];
console.log(current_month);
// -> October (Or the curent month name)
In the code snippet, we are using the .toLocaleString() method of javascript date which takes two parameters. The format of the month name that you want to get and the second parameter is an object which takes key values as the options passed to get the month.
As an alternative, we can also use the .getMonth() javascript date method which returns the month number in integer format.
Live Demo
//FUll Month name
const full_month_name = new Date().toLocaleString('default', { month: 'long' });
// -> returns full current month name e.g. October
const short_month_name = new Date().toLocaleString('default', { month: 'short' });
// -> returns short current month name e.g. Oct
const month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
const month = new Date().getMonth();
const month_name = month_names[month];
// -> returns name of month
0 Comments