无效的日期格式在javascript日期(2022,0,13)格式



我得到

{
"LeadCreatedDate": "Date(2022,0,13)" // <----- this type of date format
}

图像是否有任何方式我可以格式化它在反应任何类型的帮助将是伟大的。提前谢谢你。

日期格式图片链接

如果对API响应的格式无能为力,则必须手动解析它。

例如,您可以使用slice()提取参数部分,split()将它们分割为逗号字符以获得数组,map()将其映射为数字并将其传递给Date构造函数。

// 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);

要做到这一点,您需要在推送数据之前格式化日期。有一个信息,如何正确地做

最新更新