3

I expected toLocaleString to return "Monday" (6 character),

but IE returned some unexpected character to me,

how can i get weekday correctly without another extension API (moment.js, etc..)

IE11:

var weekday = new Date('2015-11-23').toLocaleString("en-us", { weekday: 'long'});

weekday.toString() //"Monday"
weekday.length //7
weekday.charCodeAt(0) //8206 <-- what is this

Chrome53:

var weekday = new Date('2015-11-23').toLocaleString("en-us", { weekday: 'long'});

weekday.toString() //"Monday"
weekday.length //6
weekday.charCodeAt(0) //77
Benny Leung
  • 133
  • 1
  • 3
  • 10

1 Answers1

0

OK, I did some investigating:

Character 8206 is a Left-to-right mark, most likely added in by MS as part of its internationalization rules.

It can be easily stripped out.

var stripped = weekday.replace(/\u200E/g, "");
console.log(stripped.length)

Just a note: You may also encounter character 8207, which is a right-to-left mark -- that can be stripped just as easily.

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74