Moment.js YYYY-M-DD在IE中无效

时间:2014-05-16 15:43:39

标签: javascript jquery momentjs

简单的问题。为什么值false和value2为真?只是为了好玩,价值3确实有效。 在前三个评论和一些测试后,我被迫改变了我的问题。

var value = "1970-5-29";
var value2 = "1970-05-29";
var value3 = "1970/5/29";

alert(moment(value).isValid());
alert(moment(value2).isValid());
alert(moment(value3).isValid());

The fiddle

我错过了一些关于moment.js的错误吗?或YYYY-M-DD不被普遍接受?

1 个答案:

答案 0 :(得分:1)

根据moment.js文档,这里是有效格式列表:

The following ISO-8601 formats are supported across all browsers.

"2013-02-08"
"2013-02-08T09"
"2013-02-08 09"
"2013-02-08T09:30"
"2013-02-08 09:30"
"2013-02-08T09:30:26"
"2013-02-08 09:30:26"
"2013-02-08T09:30:26.123"
"2013-02-08 09:30:26.123"
"2013-02-08T09:30:26 Z"
"2013-02-08 09:30:26 Z"
"2013-W06-5"
"2013-W06-5T09"
"2013-W06-5 09"
"2013-W06-5T09:30"
"2013-W06-5 09:30"
"2013-W06-5T09:30:26"
"2013-W06-5 09:30:26"
"2013-W06-5T09:30:26.123"
"2013-W06-5 09:30:26.123"
"2013-W06-5T09:30:26 Z"
"2013-W06-5 09:30:26 Z"
"2013-039"
"2013-039T09"
"2013-039 09"
"2013-039T09:30"
"2013-039 09:30"
"2013-039T09:30:26"
"2013-039 09:30:26"
"2013-039T09:30:26.123"
"2013-039 09:30:26.123"
"2013-039T09:30:26 Z"
"2013-039 09:30:26 Z"

If a string does not match any of the above formats and is not able to be parsed with Date.parse, moment#isValid will return false.

因为它不在该列表中,如果它不会被date.Parse()解析,它就不会显示为有效。