Javascript Safari: new Date() with strings returns

2019-06-08 10:24发布

问题:

I have a weird problem in my javascript new Date() method in Safari and Firefox but not in chrome. I have a form on my UI for a date input along with a calendar drop down. If I select a date from the calendar drop down and hit save, it calls a date method as:

var date = new Date(inputDate); // inputDate example from calendar is 12-25-2016

This works fine in Safari, Chrome and Firefox since I didn't type the date manually in the date box. However, the date object is invalid date returned by the new Date() method, IF I type the date manually via keyboard and hit save. The new Date() object returns an invalid date. Chrome is still fine and works properly even while the date is typed, but Safari and Firefox show as invalid date when typed and invoked the method. Any clue how to solve this ?

Thanks.