UPDATED - Firefox中无效的日期 [英] UPDATED - Invalid Date in Firefox
问题描述
我想在Date对象中放上以下字符串:'10 -10-2013 03:04'。
它在Chrome中正常工作,但Firefox告诉我这是无效的日期。 (我猜他们的意思是格式?)
我试图使用Date.parse,但它使它成为一个NaN。
该怎么做? >
更新:
我使用了这个答案,但现在Chrome实际上说这是无效的日期..
var dateString = '10 -10-2013 03:04';
dateString = dateString.replace(/ - / g,'');
var DateToUse = new Date(dateString);
在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中运行正常。
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.
What to do?
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);
Returns an invalid date in Chrome.
<script>
var myDate = new Date("10 10 2013 03:04");
console.log(myDate);
</script>
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.
这篇关于UPDATED - Firefox中无效的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!