Hello everyone,
I have been working on converting dates from my API using the moment.js
library. The sample collection of dates retrieved from the API looks like this:
However, I am encountering an issue where all dates are returning as 2019-12-13
, despite proper functionality in other parts of my codebase that implement moment.js.
const response = {
data: [{
'from': '2019-12-31T00:00:00',
'to': '2020-12-31T00:00:00'
},
{
'from': '2021-12-31T00:00:00',
'to': '2022-12-31T00:00:00'
},
{
'from': '2023-12-31T00:00:00',
'to': '2024-12-31T00:00:00'
}
]
}
response.data.forEach((d) => {
d.from = moment(d.from).format("YYYY-MM-DD")
d.to = moment(d.to).format("YYYY-MM-DD")
})
console.log(response.data)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>