Eugene Yu
Eugene Yu

Reputation: 3978

JavaScript new Date(string) returns different results on exactly identical date strings

I would like to share something I found with JavaScript today.

Simple example here

d1 = "2014-07-15T14:00:00.000Z"
d2 = "2014-07-15T14:00:00.000Z"

The input strings are ISO formatted using new Date().toISOString();. I received the first date from a server where it was stored in mongoDB as ISOString, and the second one was created manually.

If I do new Date(d1);, it returns 'Invalid Date' but if I do the same for d2 it returns the correct date.

Upvotes: 4

Views: 74

Answers (1)

zerkms
zerkms

Reputation: 255135

The first one contains non printable

0x20 0x3D 0x20 0x22

characters

Upvotes: 5

Related Questions