为什么 ParseInt() 在 Microsoft Edge 上返回 NaN?
Why is ParseInt() returning NaN on 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));
我得到一个 NaN;你?我在 Chrome 和 Firefox 的控制台中尝试了相同的代码,当 parseInt(a) 为 运行.
时,它们都产生“2019”
1) 为什么会这样?
2) 如何在 Microsoft Edge 中解析 "a" 变量并将其转换为整数?
我在 运行 Edge 中的片段时看到了同样的问题。
Edge 显然在使用 ToLocaleDateString()
时向字符串添加了一些隐藏格式,因此必须在使用 parseInt()
之前清除,例如 .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));
转到 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));
我得到一个 NaN;你?我在 Chrome 和 Firefox 的控制台中尝试了相同的代码,当 parseInt(a) 为 运行.
时,它们都产生“2019”1) 为什么会这样?
2) 如何在 Microsoft Edge 中解析 "a" 变量并将其转换为整数?
我在 运行 Edge 中的片段时看到了同样的问题。
Edge 显然在使用 ToLocaleDateString()
时向字符串添加了一些隐藏格式,因此必须在使用 parseInt()
之前清除,例如 .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));