imagei am getting
{
"LeadCreatedDate": "Date(2022,0,13)" // <----- this type of date format
}
is there any way i can format it in react any kind of help will be great. Thank you in advance.
CodePudding user response:
If you cannot do anything about the format of the API response, you'll have to manually parse it.
For example, you can use slice() to extract the arguments part, split() them on comma characters to get an array, map() that to numbers and pass them to the Date
constructor.
// a function to transform your date values
const parseGSheetDate = (val) =>
new Date(...val.slice(5, -1).split(",").map(Number));
// your original data
const data = {
"LeadCreatedDate": "Date(2022,0,13)",
"FullName": "Maryn Mccabe",
"FirstName": "Maryn",
"LastName": "Mccabe",
};
// replace the date fields with their parsed equivalents
const parsed = {
...data,
LeadCreatedDate: parseGSheetDate(data.LeadCreatedDate),
};
console.log(parsed);
CodePudding user response:
To do that, you need to format date before you push data. There is an information, how to do that properly