-2

I have a file there is data coming from JSON but here is format like 06/12/2020 but I have to convert this format like June 12 2020.

How can I do this?

Current Code:-

 {pageData.map(x =>
  <tr>
  <td>{x.date}</td>
  <td>{x.name}</td>
  <td>{x.language}</td>
  <td><a href={x.link} target="_blank" class="btn">Click to Listen</a></td>
  </tr>
  )}

Thank you for your efforts!

Rohit Verma
  • 3,657
  • 7
  • 37
  • 75
  • 1
    The solution you need is twofold: 1) parse `06/12/2020` into variables or a `Date` 2) output as `June 12 2020`. Both questions have tons of existing answers. –  Apr 14 '21 at 07:02
  • Does this answer your question? [How can I convert string to datetime with format specification in JavaScript?](https://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript) – Phil Apr 14 '21 at 07:02
  • Does this answer your question? [Get month name from Date](https://stackoverflow.com/questions/1643320/get-month-name-from-date) – Ravi Chaudhary Apr 14 '21 at 07:03

1 Answers1

0

base on Date doc, you just need to create a date object like this:

<td>{new Date(x.date).toLocaleDateString('en-En',{ year: 'numeric', month: 'long', day: 'numeric' })}</td>
antoineso
  • 2,063
  • 1
  • 5
  • 13
  • 1
    Parsing a date string like _"06/12/2020"_ with the `Date` constructor is not recommended – Phil Apr 14 '21 at 07:00