Get the month from JS Date Object
January 24, 2022
JavaScript’s Date Object provides the toLocaleDateString
method. The name of the month is returned by passing it a locales
string and options
object as parameters.
const dateObj = new Date()
// Set locales to desired location/language format
const locales = "en-US"
// The month property can also be set to "short"
const options = { month: "long" }
// Call method with parameters
const nameOfTheMonth = dateObj.toLocaleDateString(locales, options)
// Log/print the name of the month
console.log(nameOfTheMonth)
Click here for browser compatibility and more info about the toLocaleDateString method.