Search code examples
javascriptinternet-explorer-11

Is this a bug in IE 11?


console.log(
  ('00' + (new Date('3/4/2019')).toLocaleDateString("en-US").split('/')[1]).slice(-2)
);

IE:

"4"

Chrome

"04"

What is the workaround?


Solution

  • Why not just to get the day from the available method from the object Date.

    var day = new Date('3/4/2019').getDate();
    console.log(day >= 10 ? day : ("0" + day)); // We can use String.prototype.padStart(2, "0"), however, that's not available in IE11