0

On IE 11 browser the below statement is returning an invalid date response: new Date("2016-03-09T22:40:05.653-0800"). Where as on the chrome/firefox it is returning the valid date.

Please suggest me !!

3 Answers3

2

This is nearly an ISO-8601 formatted date/time, but not quite... the UTC offset doesn't have a colon in it. It looks like Chrome and Firefox aren't being quite as picky with their ISO-8601 parsing as IE.

If you change the code to:

new Date("2016-03-09T22:40:05.653-08:00")

... then it's fine in both Chrome and IE11. (I haven't tested Firefox, but I'd expect it to be fine.)

"-0800" is a valid UTC offset in basic format of ISO-8601, but that doesn't have colons. Neither Chrome nor IE want to handle a properly-formatted basic ISO-8601 value, e.g. "20160309T224005-0800".

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

The string given to the date constructor should be an RFC2822 or ISO 8601 formatted date. In your example it isn't. Try the following:

new Date("2012-11-02T19:30:00.000Z");
Jekin Kalariya
  • 3,475
  • 2
  • 20
  • 32
0

According to specification I believe that the timezone should be specified as -08:00.