javascriptjquerymomentjseonasdan-datetimepicker

Could not parse date parameter: Invalid Date issue in Safari and Firefox


I am trying to set the default date parameter in Bootstrap DateTimePicker. Please see the code below

date = $('#drop-off').val(); // "04-07-2018  4:22 PM"
date = moment(date);
date = date.toDate();
$(a).datetimepicker({
    format: 'MM-DD-YYYY hh:mm A',
    defaultDate: date
});

This works good in Chrome, buts throws an error both in Safari and Firefox

TypeError: defaultDate() Could not parse date parameter: Invalid Date

Is this an issue with the time format that I pass to the moment function?


Solution

  • Issue was with the moment method to format the date. Passing an additional argument with format will fix the issue.

     date =  moment(date, 'MM-DD-YYYY hh:mm A');