0

I want to format the date based on the current browser locale. Like navigator.language. This works

moment(new Date()).locale(navigator.language).format("llll");

but do I need to use the .locale(navigator.language)? I want to know if I need that explicitly, or does moment use the current locale by default, so that I would just need

moment(new Date()).format("llll");

Thanks

omega
  • 40,311
  • 81
  • 251
  • 474
  • 3
    Possible duplicate of [Locale detection with Moment.js](https://stackoverflow.com/questions/25725882/locale-detection-with-moment-js) – David Nov 10 '18 at 00:23
  • 1
    The linked answer is 4 years old. But I [checked the docs](https://momentjscom.readthedocs.io/en/latest/moment/06-i18n/01-changing-locale/) and it seems to be still true. – David Nov 10 '18 at 00:24
  • 1
    [The docs referred to in the other question](https://momentjs.com/docs/#/i18n/changing-locale/) – E. Sundin Nov 10 '18 at 00:24
  • but that answer doesn't answer my question. That only says how to change it. I want to know if it uses browser locale by default. – omega Nov 10 '18 at 00:37
  • and yes im using the moment with locale.js file – omega Nov 10 '18 at 00:38
  • You might just use `new Date().toLocaleString(undefined)`, which will use the current browser language for the locale. – RobG Nov 10 '18 at 04:34

0 Answers0