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')

That is not a standard date format. Chrome is a little more flexible, but FF is not. Try something like:

new Date('2021-02-11T12:11:00')

Take a look at some of the valid formats in the docs.

1 Like

There are also libraries like moment.js that will (if I remember correctly) allow some different formats. You could also write your own helper functions to accept/return whatever formats you want.

There is some discussion of valid date formats here.

Each browser choses how to implement JS. They all start with the basic specifications, but some may go a little beyond that and others a little behind, so you get things like you’ve discovered. It’s part of the “fun” of web development. When it doubt, check the docs.