Reputation: 1923
In react application(nextjs), I want to convert the date
format using moment
which comes under array of hashes. Data is like,
[
{
"date": "2020-12-22T00:00:00.000Z",
"price": "4365.6384226722"
},
{
"date": "2020-12-23T00:00:00.000Z",
"price": "4084.628672025"
},
{
"date": "2020-12-24T00:00:00.000Z",
"price": "3874.3753251552"
},
...
]
const formatDate = (value) => {
return moment(value).format('HH:MM A DD MM, YYYY')
}
Here, I want to change the date
format using formatDate
and return it in same data format and which I want to pass it for graph.
Please help to solve this.
Upvotes: 0
Views: 2943
Reputation: 1267
You mean this ?
const passedValue = yourArray.map(item => ({
date: formatDate(item.date),
price: item.price
}))
Upvotes: 1