xxxxxxxxxx
const date = new Date();
const month = date.toLocaleString('default', { month: 'long' });
console.log(month);
xxxxxxxxxx
let date = new Date(2020, 05, 21); // 2020-06-21
let longMonth = date.toLocaleString('en-us', { month: 'long' }); /* June */
let shortMonth = date.toLocaleString('en-us', { month: 'short' }); /* Jun */
let narrowMonth = date.toLocaleString('en-us', { month: 'narrow' }); /* J */
xxxxxxxxxx
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var d = new Date();
var monthName=months[d.getMonth()]; // "July" (or current month)
xxxxxxxxxx
const currentDate = new Date();
const currentMonth = currentDate.getMonth();
console.log(currentMonth);
xxxxxxxxxx
// Get the current date
const currentDate = new Date();
// Get the month as an index (0 - January, 1 - February, ...)
const monthIndex = currentDate.getMonth();
// Array of month names
const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Get the month name using the month index
const monthName = monthNames[monthIndex];
console.log(monthName); // Output: current month name
xxxxxxxxxx
month1 = month1.toLowerCase();
var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
month1 = months.indexOf(month1);
xxxxxxxxxx
// Create an array with the names of the months
const monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
// Get the current month (0-11 for January-December)
const currentMonthIndex = new Date().getMonth();
// Retrieve the name of the current month
const currentMonthName = monthNames[currentMonthIndex];
// Output the current month name
console.log(currentMonthName);
xxxxxxxxxx
const today = new Date()
today.toLocaleString('default', { month: 'long' })
// GET DYNAMIC MONTH STRING
const monthtostring = month => new Date(`${month}/01/2032`).toLocaleString('en-US', { month: 'long' })
monthtostring(8) // August
const monthtostring = month => new Date(`${month}/01/2032`).toLocaleString('pt-BR', { month: 'long' })
monthtostring(03) // março