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

Kwall
  • 151
  • 8

2 Answers2

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
Robb216
  • 484
  • 3
  • 8
0

using moment package

moment(moment('2020-11-18', 'YYYY-MM-DD')).format('DD MMM YYYY'); 
Mohiuddin Khan
  • 473
  • 2
  • 10