IE 11问题与JavaScript toLocaleDateString()格式 [英] IE 11 issue with JavaScript toLocaleDateString() formatting
问题描述
我正在使用JavaScript Date函数toLocaleDateString()将我的日期格式化为 8/13/2014
,但出于某种原因我尝试发送此值通过API调用,通过执行 JSON.stringify
然后AJAXing该值,IE决定将实际值更改为?8?/?30 ?/?2014
..这显然会导致后端出错。
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.
为什么IE会这样做以及如何解决?
Why does IE do this and how can I fix it?
推荐答案
看起来这是IE 11中引入的一个错误.IE 11使用Unicode字符,所以你看到的是 U + 200E'左右标记'
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'
作为解决此问题的临时解决方案,您可以做的是替换该char。像这样:
What you can do as a temporary solution to fix this issue is to replace that char. Like this:
console.log((new Date()).toLocaleDateString().replace(/\u200E/g, ''));
这篇关于IE 11问题与JavaScript toLocaleDateString()格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!