rikkitikkitumbo rikkitikkitumbo - 1 year ago 79
Javascript Question

IE Date.toLocaleTimeString().split isn't returning an array of strings

This is straight from the console in IE (Microsoft Edge 25.10):

greg = new Date().toLocaleTimeString().split(':')[0];
greg = new Date().toLocaleTimeString().split(':')[0]=="12";


Answer Source

It's because there are two invisible characters in the string: U-200E (left-to-right marks) at the beginning and end:

new Date().toLocaleTimeString().split(':')[0] == "\u200e12\u200e" // true

toLocaleTimeString is defined here by ECMA-402 if the browser supports ECMA-402; otherwise, it's completely up to the implementation. IE doesn't support ECMA-402 and thus it can put anything in that string it likes. Including left-to-right marks seems a bizarre thing to do, but...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download