moment(String) 特殊格式


moment(String, moment.CUSTOM_FORMAT, [String], [Boolean]);
moment(String, moment.HTML_FMT.DATETIME_LOCAL, [String], [Boolean]); // 从 2.20.0 开始。
moment(String, [..., moment.ISO_8601, ...], [String], [Boolean]);

ISO-8601 是时间和时长显示的标准。 Moment 已经支持解析 iso-8601 字符串,但是可以在构造 moment 时在格式/格式列表中明确地指定。

要指定 iso-8601 解析,则使用 moment.ISO_8601 常量。

moment("2010-01-01T05:06:07", moment.ISO_8601);
moment("2010-01-01T05:06:07", ["YYYY", moment.ISO_8601]);

2.20.0 版本开始,可以使用以下 HTML5 格式:

常量格式示例输入类型
moment.HTML5_FMT.DATETIME_LOCALYYYY-MM-DDTHH:mm2017-12-14T16:34<input type="datetime-local" />
moment.HTML5_FMT.DATETIME_LOCAL_SECONDSYYYY-MM-DDTHH:mm:ss2017-12-14T16:34:10<input type="datetime-local" step="1" />
moment.HTML5_FMT.DATETIME_LOCAL_MSYYYY-MM-DDTHH:mm:ss.SSS2017-12-14T16:34:10.234<input type="datetime-local" step="0.001" />
moment.HTML5_FMT.DATEYYYY-MM-DD2017-12-14<input type="date" />
moment.HTML5_FMT.TIMEHH:mm16:34<input type="time" />
moment.HTML5_FMT.TIME_SECONDSHH:mm:ss16:34:10<input type="time" step="1" />
moment.HTML5_FMT.TIME_MSHH:mm:ss.SSS16:34:10.234<input type="time" step="0.001" />
moment.HTML5_FMT.WEEKYYYY-[W]WW2017-W50<input type="week" />
moment.HTML5_FMT.MONTHYYYY-MM2017-12<input type="month" />
moment(String, moment.CUSTOM_FORMAT, [String], [Boolean]);
moment(String, moment.HTML_FMT.DATETIME_LOCAL, [String], [Boolean]); // from 2.20.0
moment(String, [..., moment.ISO_8601, ...], [String], [Boolean]);

ISO-8601 is a standard for time and duration display. Moment already supports parsing iso-8601 strings, but this can be specified explicitly in the format/list of formats when constructing a moment.

To specify iso-8601 parsing use moment.ISO_8601 constant.

moment("2010-01-01T05:06:07", moment.ISO_8601);
moment("2010-01-01T05:06:07", ["YYYY", moment.ISO_8601]);

As of version 2.20.0, the following HTML5 formats are available:

ConstantFormatExampleInput Type
moment.HTML5_FMT.DATETIME_LOCALYYYY-MM-DDTHH:mm2017-12-14T16:34<input type="datetime-local" />
moment.HTML5_FMT.DATETIME_LOCAL_SECONDSYYYY-MM-DDTHH:mm:ss2017-12-14T16:34:10<input type="datetime-local" step="1" />
moment.HTML5_FMT.DATETIME_LOCAL_MSYYYY-MM-DDTHH:mm:ss.SSS2017-12-14T16:34:10.234<input type="datetime-local" step="0.001" />
moment.HTML5_FMT.DATEYYYY-MM-DD2017-12-14<input type="date" />
moment.HTML5_FMT.TIMEHH:mm16:34<input type="time" />
moment.HTML5_FMT.TIME_SECONDSHH:mm:ss16:34:10<input type="time" step="1" />
moment.HTML5_FMT.TIME_MSHH:mm:ss.SSS16:34:10.234<input type="time" step="0.001" />
moment.HTML5_FMT.WEEKYYYY-[W]WW2017-W50<input type="week" />
moment.HTML5_FMT.MONTHYYYY-MM2017-12<input type="month" />