I am using the JavaScript Date function toLocaleDateString() to format my date to look like 8/13/2014
, but for some reason when I try to send this value via an API call by doing a JSON.stringify
and then AJAXing the value, IE decides to change the actual value to be ?8?/?30?/?2014
.. This obviously causes errors on the back end.
Why does IE do this and how can I fix it?
You should check out the answer here: ToLocaleDateString() changes in IE11
Although the function returns a string, it's only human-readable and is never appropriate for machine parsing. I'm not 100% sure what encoding it is for IE, but although it looks like a string, underneath it uses a different encoding.
For date formatting, you may wish to use Moment.js, or just write your own formatting function.
Looks like it's a bug that was introduced in IE 11. IE 11 uses Unicode chars, so what you see is U+200E 'LEFT-TO-RIGHT MARK'
What you can do as a temporary solution to fix this issue is to replace that char. Like this: