Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
36 lines (25 sloc) 949 Bytes
title version signature
Loading locales in NodeJS

Loading locales in NodeJS is super easy. If there is a locale file in moment/locale/ named after that key, import it first, then call moment.locale to load it.

var moment = require('moment');
// import moment from 'moment';

// import locale file(s)
import 'moment/locale/fr';

moment(1316116057189).fromNow(); // il y a 6 ans

To save the step of loading individual locales (i.e. just load them all), import the moment/min/moment-with-locales module instead.

import moment from 'moment/min/moment-with-locales';

moment(1316116057189).fromNow(); // vor 6 Jahren

If you want your locale supported, create a pull request to the develop branch with the required locale and unit test files.