I'm having trouble understanding what is going on with some JavaScript that seems to behave differently in Edge. Specifically boiled it down to:
var testi = new Date().toLocaleTimeString();
var len2 = testi.length;
alert(len2);
My length in Edge is 17, in Chrome and IE it's 10 There seems to be some phantom spaces in the string, it also screwed up my attempting to substring it.
https://jsfiddle.net/m1m8h7ym/
FYI my Time Zone is US Central.
Looks like Microsoft is slipping in the invisible left-to-right mark. This also occurs in IE11 in Edge mode. I figured this out by looping through each character in the string and passing it to encodeURIComponent()
var output = document.getElementById("output");
var testi = new Date().toLocaleTimeString();
var row;
for (var i = 0, len = testi.length; i < len; i++) {
row = document.createElement("pre");
row.innerHTML = encodeURIComponent(testi[i]);
output.appendChild(row);
}
<div id="output"></div>
You could strip it out by removing it by its unicode, which can be captured in regex by the expression \u200E
.
var output = document.getElementById("output");
var testi = new Date().toLocaleTimeString().replace(/\u200E/g,"");
var row;
for (var i = 0, len = testi.length; i < len; i++) {
row = document.createElement("pre");
row.innerHTML = encodeURIComponent(testi[i]);
output.appendChild(row);
}
<div id="output"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With