Firefox中的无效日期-Javascript [英] Invalid Date in Firefox - Javascript
问题描述
我想在Date对象中放置以下字符串:'10 -10-2013 03:04'.它可以在Chrome浏览器中运行,但Firefox告诉我这是一个无效的日期.(我猜他们是指格式吗?)我尝试在其上使用Date.parse,但这使其成为NaN.
I want to put the following string: '10-10-2013 03:04' in a Date object. It's working in Chrome but Firefox tells me it's an invalid Date. (I guess they mean format?) I tried to use Date.parse on it but that makes it a NaN.
该怎么办?
更新:我用了thefourtheye的答案,但现在Chrome实际上说这是一个无效的日期..
UPDATE: I used the answer of thefourtheye, but now Chrome actually says it's an invalid date ..
var dateString = '10-10-2013 03:04';
dateString = dateString.replace(/-/g, ' ');
var DateToUse = new Date(dateString);
在Chrome中返回无效的日期.
Returns an invalid date in Chrome.
推荐答案
<script>
var myDate = new Date("10 10 2013 03:04");
console.log(myDate);
</script>
根据标准, http://tools.ietf.org/html/rfc2822#page-14 ,可以使用空格分隔日期,月份和年份.上面的示例在Chrome和Firefox中完美运行.
According to the standard, http://tools.ietf.org/html/rfc2822#page-14, space can be used to separate date, month and year. The above example works perfectly in Chrome and Firefox.
这篇关于Firefox中的无效日期-Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!