Rai*_*r94 3 javascript parseint microsoft-edge
转到 Microsoft Edge 控制台并运行以下 JavaScript:
current_date = new Date().toLocaleDateString("en-CA",{timeZone: "America/Los_Angeles"});
a = current_date.substring(0,current_date.indexOf('-'));
console.log(parseInt(a));Run Code Online (Sandbox Code Playgroud)
我得到一个 NaN;你?我在 Chrome 和 Firefox 的控制台中尝试了相同的代码,当运行 parseInt(a) 时,它们都产生“2019”。
1)为什么会发生这种情况?
2) 如何在 Microsoft Edge 中解析“a”变量并将其转换为整数?
在 Edge 中运行代码片段时,我看到了同样的问题。
Edge 显然在使用时向字符串添加了一些隐藏格式,因此在使用或 类似ToLocaleDateString()之前必须清除这些格式parseInt()Number().replace(/\u200E/g, '');
current_date = new Date().toLocaleDateString("en-CA",{timeZone: "America/Los_Angeles"}).replace(/\u200E/g, '');
a = current_date.substring(0,current_date.indexOf('-'));
console.log(parseInt(a));
console.log(Number(new Date().toLocaleDateString("en-GB", {day: "numeric"}).replace(/\u200E/g, '')));Run Code Online (Sandbox Code Playgroud)