By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.

    To load a locale, pass the key and the string values to .

    More details on each of the parts of the locale bundle can be found in the section.

    1. moment.locale('fr', {
    2. months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
    3. monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
    4. monthsParseExact : true,
    5. weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
    6. weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
    7. weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
    8. weekdaysParseExact : true,
    9. longDateFormat : {
    10. LT : 'HH:mm',
    11. LTS : 'HH:mm:ss',
    12. L : 'DD/MM/YYYY',
    13. LL : 'D MMMM YYYY',
    14. LLL : 'D MMMM YYYY HH:mm',
    15. LLLL : 'dddd D MMMM YYYY HH:mm'
    16. },
    17. calendar : {
    18. sameDay : '[Aujourd’hui à] LT',
    19. nextDay : '[Demain à] LT',
    20. nextWeek : 'dddd [à] LT',
    21. lastDay : '[Hier à] LT',
    22. lastWeek : 'dddd [dernier à] LT',
    23. },
    24. future : 'dans %s',
    25. past : 'il y a %s',
    26. s : 'quelques secondes',
    27. m : 'une minute',
    28. mm : '%d minutes',
    29. h : 'une heure',
    30. hh : '%d heures',
    31. d : 'un jour',
    32. dd : '%d jours',
    33. M : 'un mois',
    34. MM : '%d mois',
    35. y : 'un an',
    36. yy : '%d ans'
    37. },
    38. dayOfMonthOrdinalParse : /\d{1,2}(er|e)/,
    39. ordinal : function (number) {
    40. return number + (number === 1 ? 'er' : 'e');
    41. },
    42. meridiemParse : /PD|MD/,
    43. isPM : function (input) {
    44. },
    45. // In case the meridiem units are not separated around 12, then implement
    46. // this function (look at locale/id.js for an example).
    47. // return /* 0-23 hour, given meridiem token and hour 1-12 */ ;
    48. // },
    49. meridiem : function (hours, minutes, isLower) {
    50. return hours < 12 ? 'PD' : 'MD';
    51. },
    52. week : {
    53. dow : 1, // Monday is the first day of the week.
    54. doy : 4 // Used to determine first week of the year.
    55. }
    56. });

    Once you load a locale, it becomes the active locale. To change active locales, simply call moment.locale with the key of a loaded locale.

    As of 2.21.0, Moment will console.warn if the locale is unavailable.

    As of 2.8.0, changing the global locale doesn't affect existing instances.

    1. moment.locale('fr');
    2. var m = moment(1316116057189);
    3. m.fromNow(); // il y a une heure
    4. moment.locale('en');
    5. m.fromNow(); // il y a une heure
    6. moment(1316116057189).fromNow(); // an hour ago

    You may also specify a list of locales, and Moment will use the first one it has localizations for.

    1. moment.locale(['tq', 'fr']); // 'fr'

    Moment will also try locale specifier substrings from most-specific to least-specific until it finds a locale it knows. This is useful when supplying Moment with a locale string pulled from the user's environment, such as window.navigator.language.

    Finally, Moment will search intelligently through an array of locales and their substrings.