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";
var startDateTime = moment(startDate + ' ' + startTime);
alert(moment(startDateTime).format("D-MMM-YYYY h:mm A"));
IE and Chrome just return "Invalid Date"
any ideas what im missing?
isValid() is the method available on moment which tells if the date is valid or not. MomentJS also provides many parsing flags which can be used to check for date validation.
MomentJS is a widely used time and date formatting and calculation library.
You do not need Moment. js if you support newer browsers and if you show dates or datetimes only in your user's timezone. Things are not as easy as they seem, especially if you plan on manually parsing the output from the native APIs.
Mutability 1.0.The moment object in Moment. js is mutable. This means that operations like add, subtract, or set change the original moment object.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With