The following piece of code gets the month from a date
object in JavaScript.
const date = new Date(dateValue);
const month = date.toLocaleString('default', { month: 'short' });
For example: if the date is something like 30/07/2019
it will return Nov
.
This works fine in Chrome but fails in Edge browser with error:
SCRIPT5121: SCRIPT5121: Locale 'default' is not well-formed
My Edge browser version is 41.16299.1004.0
Here's a jsfiddle: https://jsfiddle.net/1dwcv9xu/1
As per MDN, date.toLocaleString
is fully supported in Edge: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString#Browser_compatibility.
Also I couldn't find this error code in the MSDN docs for Edge: https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide/console/error-and-status-codes.
Is there a way to fix this or any alternate approach to get the month in mmm
format?