Moment.js works with valid date on Chrome but not IE or Firefox

前端 未结 1 1634
隐瞒了意图╮
隐瞒了意图╮ 2021-02-15 00:57

So this works fine in Chrome but not IE(11) and Firefox

 var startDate = moment(\"12-Nov-2015\").format(\"D-MMM-YYYY\");
        var startTime = \"10:00 AM\";

          


        
相关标签:
1条回答
  • 2021-02-15 01:14

    This would be because "12-Nov-2015" is not a valid ISO 8601 format therefore MomentJS falls back to the browser parser which is quite different according to the browser. So this issue would be caused because Google Chrome accepts that format but not IE or Firefox, not an issue with Moment.

    Please see this link for more details: http://momentjs.com/docs/#/parsing/string/

    As their documentation states, if using a non ISO 8601 format specify the format of the string when parsing, using http://momentjs.com/docs/#/parsing/string-format/

    So

    var startDate = moment("12-Nov-2015").format("D-MMM-YYYY");
    

    Should be

    var startDate = moment("12-Nov-2015", "D-MMM-YYYY").format("D-MMM-YYYY");
    

    Please see here for information in date parsing inconsistencies: http://dygraphs.com/date-formats.html

    0 讨论(0)
提交回复
热议问题