When creating a moment from a string, we first check if the string matches known formats, we then check if the string matches the RFC 2822 Date time format before dropping to the fall back of if a known format is not found.

    1. var day = moment("1995-12-25");

    Warning: Browser support for parsing strings . Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.

    For consistent results parsing anything other than ISO 8601 strings, you should use String + Format.

    Supported ISO 8601 strings

    An ISO 8601 string requires a date part.

    1. 2013-02-08T09 # An hour time part separated by a T
    2. 2013-02-08 09 # An hour time part separated by a space
    3. 2013-02-08 09:30 # An hour and minute time part
    4. 2013-02-08 09:30:26 # An hour, minute, and second time part
    5. 2013-02-08 09:30:26.123 # An hour, minute, second, and millisecond time part
    6. 2013-02-08 24:00:00.000 # hour 24, minute, second, millisecond equal 0 means next day at midnight
    7. 20130208T080910,123 # Short date and time up to ms, separated by comma
    8. 20130208T080910 # Short date and time up to seconds
    9. 20130208T0809 # Short date and time up to minutes
    10. 20130208T08 # Short date and time, hours only

    Any of the date parts can have a time part.

    If a time part is included, an offset from UTC can also be included as +-HH:mm, +-HHmm, +-HH or Z.

    1. 2013-02-08 09+07:00 # +-HH:mm
    2. 2013-02-08 09-0100 # +-HHmm
    3. 2013-02-08 09:30:26.123+07:00 # +-HH:mm
    4. 2013-02-08 09:30:26.123+07 # +-HH

    Note: Support for the week and ordinal formats was added in version 2.3.0.

    The RFC 2822 date time format

    Before parsing a RFC 2822 date time the string is cleansed to remove any comments and/or newline characters. The additional characters are legal in the format but add nothing to creating a valid moment instance.

    After cleansing, the string is validated in the following space-separated sections, all using the English language:

    1. 6 Mar 17 21:22 UT
    2. 6 Mar 17 21:22:23 UT
    3. 6 Mar 2017 21:22:23 GMT
    4. Mon 06 Mar 2017 21:22:23 z
    • Day of Week in three letters, followed by an optional comma. (optional)
    • Day of Month (1 or 2 digit), followed by a three-letter month and 2 or 4 digit year
    • Two-digit hours and minutes separated by a colon (:), followed optionally by another colon and seconds in 2-digits
    • Timezone or offset in one of the following formats:
    • UT : +0000
    • GMT : +0000
    • EST | CST | MST | PST | EDT | CDT | MDT | PDT : US time zones*
    • A - I | K - Z : Military time zones*
    • Time offset +/-9999
      [*] See of the specification for details.

    The parser also confirms that the day-of-week (when included) is consistent with the date.