Can you help me in formatting a UTC date into a textual representation in a local language (Dutch to be specific).
The code
var realDate = moment.utc(birthday);
var now = moment();
birthdayToday = (realDate.month() == now.month() && realDate.date() == now.date());
data.Birthdays.push({
Name: preferredName,
Birthday: birthdayToday ? 'Today!' : realDate.format("MMMM D"),
Path: path,
PhotoUrl: photoUrl,
AccountName: accountName,
BirthdayIsToday: birthdayToday
});
Because of the line realDate.format("MMMM D"), this current displays as May 31, June 6 etc. What I want is 31 Mei, 6 Juni (dutch dates).
I dont see a clear example in the documentation on how to use format with a local language
Any help appreciated!
Can you help me in formatting a UTC date into a textual representation in a local language (Dutch to be specific).
The code
var realDate = moment.utc(birthday);
var now = moment();
birthdayToday = (realDate.month() == now.month() && realDate.date() == now.date());
data.Birthdays.push({
Name: preferredName,
Birthday: birthdayToday ? 'Today!' : realDate.format("MMMM D"),
Path: path,
PhotoUrl: photoUrl,
AccountName: accountName,
BirthdayIsToday: birthdayToday
});
Because of the line realDate.format("MMMM D"), this current displays as May 31, June 6 etc. What I want is 31 Mei, 6 Juni (dutch dates).
I dont see a clear example in the documentation on how to use format with a local language
Any help appreciated!
Share Improve this question asked May 27, 2014 at 13:43 JurgenWJurgenW 3172 gold badges5 silver badges18 bronze badges 2 |3 Answers
Reset to default 10Changing the locale globally:
moment.locale('nl');
And make sure you also load the moment-with-locales.(min.)js file
Something like this?
var today = moment()
today.lang('de')
console.debug(today.calendar())
console.debug(moment().calendar())
Result:
Heute um 15:54 Uhr
Today at 3:54 PM
Remember to include moment-with-langs.js
instead of the simple moment.js
. Also remember that .lang
provides instance specific configuration, so you will have to call .lang('de')
for each moment instance that you want to use in German.
Or if you want global configuration:
moment.lang('de') //<-- call not on the instance, but on the moment function
var today = moment()
console.debug(today.calendar())
console.debug(moment().calendar())
Result:
Heute um 15:54 Uhr
Heute um 15:54 Uhr
Moment with langs CDN
You can change moment locale globally like that:
import moment from 'moment';
import localization from 'moment/locale/fr';
moment.locale('fr', localization);
I hope this helps you.
realDate.lang('nl')
andrealDate.format('D MMMM')
. It seems you'll have to add support for Dutch (nl) though as it doesn't seem to have default support. – RobG Commented May 27, 2014 at 14:08