The string I have : 2021-11-02T00:00:00.000Z . I need to display this as November 02, 2021.
Could someone please help me with this?
CodePudding user response:
You can do something like this in vanilla JS
const options = { year: 'numeric', month: 'long', day: 'numeric' };
console.log(new Date('2021-11-02T00:00:00.000Z').toLocaleDateString("en-US", options));
CodePudding user response:
You would want to use what Date class has provided, here's a complete example.
const date = new Date('2021-11-02T00:00:00.000Z')
const month = date.toLocaleString('default', {
month: 'long'
})
const day = date.getDay()
const year = date.getFullYear()
console.log(`${month} ${day}, ${year}`)