javascript 日期 (2022,0,13) 格式中的无效日期格式
invalid date format in javascript Date(2022,0,13) format
我收到了
{
"LeadCreatedDate": "Date(2022,0,13)" // <----- this type of date format
}
image
有什么方法可以让我格式化它以做出反应,任何类型的帮助都会很棒。提前谢谢你。
date format image link
为此,您需要在推送数据之前格式化日期。 There is 一条信息,如何正确地做到这一点
如果您无法对 API 响应的格式进行任何操作,则必须手动解析它。
例如,您可以将 slice() to extract the arguments part, split() them on comma characters to get an array, 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);
我收到了
{
"LeadCreatedDate": "Date(2022,0,13)" // <----- this type of date format
}
image 有什么方法可以让我格式化它以做出反应,任何类型的帮助都会很棒。提前谢谢你。
date format image link
为此,您需要在推送数据之前格式化日期。 There is 一条信息,如何正确地做到这一点
如果您无法对 API 响应的格式进行任何操作,则必须手动解析它。
例如,您可以将 slice() to extract the arguments part, split() them on comma characters to get an array, 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);