Converting string to Datetime is showing Invalid Date error in Firefox browser

In my AngularJs application, I am getting the date in string format which I need to convert to datetime and show in a datepicker. It’s working in Chrome but in Firefox converting string to datetime is showing “Invalid Date” error. I have used below code

new Date('02-11-2021 07:11 PM')

Firefox is a bit more restrictive in terms of what date formatting is allowed.

The Firefox Date documentation says that two different types of formats that are allowed. IETF-compliant RFC 2822 timestamps, but preferred with date strings is version of ISO8601.

1 Like

Worth pointing out MDN discourages using date strings for construction at all, instead pointing to either passing the timestamp as integer, or the integer values of year, monthIndex (Month - 1), and then optionally the day, hours, minutes, seconds, and milliseconds parameters.

new Date(2021,1,11,19,11);
new Date(1613088660000);
<- Date Thu Feb 11 2021 19:11:00 GMT-0500 (Eastern Standard Time)

(the timestamp may obviously be different, depending on what time zone you are in.)


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.