How to display the date month and year in a specific format using javascript and react?

Viewed 658

i have the date in this format

const title = "2020-08-23T00:00:00.000Z"

i want to display this as August 19th, 2020

i have tried using below

<div>{moment(title).format('MMMM D')</div>

and this gives output like below

August 19

how can i modify the above to get output like August 19th, 2020 using javascript.

could someone help me with this.

thanks.

2 Answers

You can use the following:

moment(yourString).format('MMMM Do, YYYY');

Where: 'MMMM' --> month, capital, full length

'Do' --> day with order

'YYYY' --> year

To format date like "August 19th, 2020" use:

moment().format("MMMM Do, YYYY")

Read the documentation to find more about different date formatting options.

Related