0

I am trying to format my date in React/ typescript project, however the data is from an api, so I can map over the data and display it but how do I convert it to a format like '22 June 2021'?

The data from the api is in format:

[
    {
       "title": 'First',
       "date": "2020-07-22T13:22:10.2566789+00:00", 
    }
]

in template binding as:

const Component = () => {
    {data.map(inner => {
        return (
        <p>{inner.title}</p>
        <p>{inner.date}</p>
        )
    })}
}

question is where and how do I convert the date, so I can bind it into the template?

Sole
  • 3,100
  • 14
  • 58
  • 112
  • 1
    The date string is in ISO 8601 format so it can be parsed into a `Date` instance (`const date = new Date(inner.date)`). There are numerous examples of how to format `Date` instances once you have them – Phil Oct 14 '21 at 23:21
  • The react-intl library also has excellent date formatting utilities – Phil Oct 14 '21 at 23:24
  • thanks, I think what I am trying to wrap my head around is how I would bind the new value into the template? – Sole Oct 14 '21 at 23:30

0 Answers0