Matt Hintzke
Matt Hintzke

Reputation: 8004

IE does not like toLocaleDateString() in API

I need to pass a date in the format 10/9/2014 to our API, but I cannot use toLocaleDateString in IE because it turns it into ?10?/?9?/?2014 because IE loves to encode things differently. Is there another simple way of getting a date into this format that is clean across the API in all browsers?

Upvotes: 3

Views: 534

Answers (1)

OJay
OJay

Reputation: 4921

I have came across this behavior as well. IE11 (fairly confident it only started happening in IE11) was putting in Unicode character \u200E (Left to right mark) when you use toLocaleDateString. I would consider this a bug and undesirable behavior , and as such I submitted a ticket on Microsoft Connect (unsure if they consider it as the same). Current the ticket is still active. Please add a repro on it too hopefully Microsoft will get around to dealing with it and making it behave as we expect it to. Ticket can be found here

There is a temporary workaround of the following

datevar.toLocaleDateString().replace(/[\u200E]/g, "")

this should sanitize your LocaleDateString and get it to behave

There is a related SO question here, which indicates that the primary issue is that we are expected the string returned from toLocaleDateString to be parsable back into a date. Which it is not intended to be. IMO I think it should be, and IE11 seems to be the odd one out here (Other browser don't do it)

Upvotes: 2

Related Questions