I have an array of object like this:
const days = [
{
_id: 12312323
date : '30/12/2021'
dateStatus : 'presence'
},
...
]
and I want to convert the date property from string to date object this way:
const convertToDateObject = (dateString: string): Date => {
const dateParts: any[] = dateString.split("/");
return new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]);
};
for (let i = 0; i < days.length; i++) {
const d = days[i].date as string;
days[i].date = convertToDateObject(d);
}
But this returns this converts the date value to this format 'Wed Dec 01 2021 00:00:00 GMT+0100 (Central European Standard Time)' instead of this format 2021-11-30T23:00:00.000Z**.
I am actually lost because when the given object does not have the _id property the formatting is working properly and it returns the wanted format, but when it does have the _id property then it returns me another format. Why?
Wed Dec 01 2021 00:00:00 GMT+0100 (Central European Standard Time). But if you need its ISO representation in UTC, then use the following:new Date().toISOString()convertToDateObject(d)then it is good format, but the problem is happening when i am affecting this value todays[i].date = ...