0

Used ng prime datepicker in application.

Getting date in Fri May 14 2021 00:00:00 GMT+0530 (India Standard Time) format as response from api.

Then converting Fri May 14 2021 00:00:00 GMT+0530 (India Standard Time) this response with new Date().

Then binding the response to ng prime datepiker.

Working fine in chrome. In firefox it is showing "Invalid date".

Shanik
  • 25
  • 5
  • See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG May 18 '21 at 20:12

2 Answers2

1

See the documentation for the Date constructor:

A string value representing a date, specified in a format recognized by the Date.parse() method. (These formats are IETF-compliant RFC 2822 timestamps, and also strings in a version of ISO8601.)

Since you aren't passing one of those formats, you are dependent on implementations having non-standard support for your format.

Chrome does. Firefox doesn't.

Use a date parsing library that lets you specify the format (such as date-fns/parse) or change the API so it outputs dates in the standard format.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You can as well, use the dateStringToDate function in date-fran module. It converts date formats of the form "Fri May 14 2021" to actual date instances.

Chukwunazaekpere
  • 906
  • 1
  • 6
  • 13