我已经在这里发布了一个问题。但答案仅适用于 Chrome,不适用于 IE(11)。我如何修复IE?ajax 从 Net 获取的日期时间:/Date(1556895600000+0900)/const parse = str => { let [_, timestamp, offsetHours, offsetMinutes] = str.match(/(\d+)\+(\d\d)(\d\d)/).map(Number); let date = new Date(timestamp); date.setHours(date.getHours() + offsetHours); date.setMinutes(date.getMinutes() + offsetMinutes); return date;}console.log( parse("/Date(1556895600000+0900)/") .toJSON())
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
只需将您拥有的 ES6 代码转换为 ES5,就不会阻塞 Internet Explorer
function parse(str) {
var result = str.match(/(\d+)\+(\d\d)(\d\d)/).map(Number),
// _ = result[0], // never used, but included for completeness
timestamp = result[1],
offsetHours = result[2],
offsetMinutes = result[3],
date = new Date(timestamp);
date.setHours(date.getHours() + offsetHours);
date.setMinutes(date.getMinutes() + offsetMinutes);
return date;
}
console.log(
parse("/Date(1556895600000+0900)/")
.toJSON()
)
添加回答
举报
0/150
提交
取消