Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  123] [ 5]  / answers: 1 / hits: 26611  / 10 Years ago, tue, may 27, 2014, 12:00:00

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!


More From » momentjs

 Answers
0

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


[#70840] Saturday, May 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonathoncamrynv

Total Points: 339
Total Questions: 98
Total Answers: 98

Location: Saint Vincent and the Grenadines
Member since Thu, Oct 15, 2020
4 Years ago
;