I am using the Javascript Date
function in my application. I have an object message
with this data
{
"attachments": "[]",
"created_on": "2024-05-09 05:19:56.677747+00:00",
"message": "{"room":"e08f1714-2558-4d73-b7f4-67dced45ace4"}",
"msg_id": 3161,
"status": "completed",
"temp_id": null,
"user_id": 13064
}
I am using the Date function like this
const messageDate = message.created_on;
console.log(new Date(messageDate))
In my ReactJS app I am getting this output:
Fri May 24 2024 15:37:39 GMT+0530 (India Standard Time)
but in my React Native app I am getting
Date { NaN }
The behaviour is kind of strange I used the following function to get the same result
const normalizeDateString = (dateString) => {
return dateString.replace(' ', 'T').replace(/s+/g, '');
};
Why is the output of the same function different in two different places? This is quite strange. Can someone explain the root cause of this?
2