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

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

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

        var startDateTime = moment(startDate + ' ' + startTime);
alert(moment(startDateTime).format("D-MMM-YYYY h:mm A"));

IE and Chrome just return "Invalid date"

any ideas that are missing?

+4
source share
1 answer

This would be because "12-Nov-2015" is not a valid ISO 8601 format, so MomentJS is returning to the browser parser, which is different from the browser. Thus, this problem will be caused by the fact that Google Chrome accepts this format, but not IE or Firefox, and not a problem with Moment.

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

, ISO 8601 , http://momentjs.com/docs/#/parsing/string-format/

,

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

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

. : http://dygraphs.com/date-formats.html

+7

Source: https://habr.com/ru/post/1616023/


All Articles