Moment.js gives Invalid date in Firefox

后端 未结 2 1721
悲哀的现实
悲哀的现实 2020-11-28 15:27

I have a requirement to convert date time in moment.js. But it gives me different result in Chrome and Firefox.

In Google Chrome it gives correct result but in Mozi

2条回答
  •  醉梦人生
    2020-11-28 16:01

    It's recommended to avoid using moment parsing with custom format. As the documentation states:

    Warning: Browser support for parsing strings is inconsistent. 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.

    In your case, the code for consistent parsing will be:

    moment('2016-Jan-02 02:00 AM', 'YYYY-MMM-DD HH:mm A')
    

提交回复
热议问题