Changing locales locally1.7.0+

  1. // From version 2.8.1 onward
  2. moment().locale(String|Boolean);
  3. // Deprecated version 2.8.1
  4. moment().lang(String|Boolean);

A global locale configuration can be problematic when passing around moments that may need to be formatted into different locale.

  1. moment.locale('en'); // default the locale to English
  2. var localLocale = moment();
  3. localLocale.locale('fr'); // set this instance to use French
  4. localLocale.format('LLLL'); // dimanche 15 juillet 2012 11:01
  5. moment().format('LLLL'); // Sunday, July 15 2012 11:01 AM
  6. moment.locale('es'); // change the global locale to Spanish
  7. localLocale.format('LLLL'); // dimanche 15 juillet 2012 11:01
  8. moment().format('LLLL'); // Domingo 15 Julio 2012 11:01
  9. localLocale.locale(false); // reset the instance locale
  10. localLocale.format('LLLL'); // Domingo 15 Julio 2012 11:01
  11. moment().format('LLLL'); // Domingo 15 Julio 2012 11:01

If you call moment#locale with no parameters, you get back the locale configuration that would be used for that moment.

  1. var fr = moment().locale('fr');
  2. fr.localeData().months(moment([2012, 0])) // "janvier"
  3. fr.locale('en');
  4. fr.localeData().months(moment([2012, 0])) // "January"

If you need to access the locale data for a moment, this is the preferred way to do so.

As of 2.3.0, you can also specify an array of locale identifiers. It works the same way it does in the global locale configuration.