0

When I tried to convert 2020-12-14 to 14 Dec 2020 by using 1st Method

<small>{item.date}</small>

2nd Method

{new Date(item.date).toLocaleString()}

then I got below output

2020-12-14
12/14/2020, 5:30:00 AM

Is there any way to convert the date format from 2020-12-14 to 14 Dec 2020.? in reactjs

2 Answers 2

1

A small modification to this elegant answer by Dave splits the toString date string into an array and formats it into the result you want. Check the code below:

const date = new Date(2020, 11, 14).toString().split(" ");
// ["Mon", "Dec", "14", "2020", "14:05:53", "GMT+0100", "(Central", "European", "Standard", "Time)"]
console.log(date[2] + " " + date[1] + " " + date[3]);
// 14 Dec 2020

Sign up to request clarification or add additional context in comments.

Comments

0

using moment package

moment(moment('2020-11-18', 'YYYY-MM-DD')).format('DD MMM YYYY'); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.