Moment.js returning NaN in Firefox but not chrome

2019-06-19 00:44发布

I have the following line of code:

moment("11-10-2013 09:03 AM").diff(moment(),"minutes");

In Chrome 30.0.1599.101, the following line return a number (It will change every minute so the exact value is not relevant).

In Firefox 25.0, it returns NaN.

I am using the moment.js 2.4.0.

Does anyone understand why this works in Chrome and not FF? I have a feeling it has to do with the way Chrome and Firefox parse date string, but haven't been able to put my finger on the exact reason.

2条回答
We Are One
2楼-- · 2019-06-19 01:06

Try this

console.log(moment().diff(moment("11-10-2013 09:03 AM", "DD-MM-YYYY hh:mm A"), "minute"));

JSFiddle

查看更多
劫难
3楼-- · 2019-06-19 01:22

Date.parse("11/10/2013 09:03 AM") or Date.parse("11 10 2013 09:03 AM") seem to work in firefox. Chrome seems to be more permissible with delimiters, allowing ., -, and even ; but what's standard it'll only be possible to tell by looking at specifications.

查看更多
登录 后发表回答