如何在JS中将字符串转换为时间戳和日期。 这里使用的是 Date.parse(),但它在 IE 和 FF 中不起作用。 我的代码是..
在 chrome 中它工作正常。
var str = "05-Sep-2013 01:05:15 PM ";
console.log( Date.parse( str ) );
console.log( Date.parse( str.replace(/-/g, '/') ) ); // 1378404315000
在 IE 中返回
console.log( Date.parse( str.replace(/-/g, '/') ) ); // NaN
请帮帮我。提前致谢。
最佳答案
不要将“-”替换为“/”,而是使用空格。
var str = "05-Sep-2013 01:05:15 PM ";
console.log( Date.parse( str.replace(/-/g, ' ') ) );
在 IE 中对我有用
看看w3schools - 他们正在处理空格 :)
关于javascript - Date.parse() 在 IE 和 FireFox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39160134/