1

I'm trying to format a date into german locale with moment.js, Version 2.11.0:

var moment = require('moment');
moment.locale("de");

console.log(moment(new Date()).locale('de').format('L'));
console.log(moment(new Date()).locale('de_DE').format('L'));

The response remains in english format:

01/05/2016

01/05/2016

Also, the following code should return something in french:

var moment = require('moment');
moment.locale('fr');
console.log( moment(1316116057189).fromNow() );  

il y a une heure

But it prints:

4 years ago

I followed the instructions on the docs. But either they are wrong or i misunderstood... Anyhow, the locale-method isn't working as expected. I installed moment with npm into an react native project. It contains lots of locale-files under a subdirectory. So, missing files could not be the root cause of this issue.

Update:

According to the comments, changing the require-statement to this one will work:

var moment = require('moment/min/moment-with-locales.js');
Community
  • 1
  • 1
delete
  • 18,144
  • 15
  • 48
  • 79
  • What do you think the german **short** date format is? –  Jan 05 '16 at 17:26
  • 1
    this would be "05.01.2016" – delete Jan 05 '16 at 17:28
  • There is the locale formatting option, but this will not calculate the offset with the local machine time.. – Pogrindis Jan 05 '16 at 17:30
  • I'm going to assume you have the `moment locales.js` ? – Pogrindis Jan 05 '16 at 17:31
  • i use require js. And yes, in node_modules is a buch of localfiles from momentjs – delete Jan 05 '16 at 17:32
  • right, and you're sure require is using them ? Also RE : http://momentjs.com/docs/#/parsing/string-format/ – Pogrindis Jan 05 '16 at 17:33
  • @xkcd149 This is no duplicate. I considered your link before asking by myself. The solution printed there isnt working either – delete Jan 05 '16 at 17:33
  • @Pogrindis: no, i'm not sure... i'm just the consumer of a library and expect that it will work as documented :) – delete Jan 05 '16 at 17:34
  • Can you provide an example replicating the issue with jsbin? – xkcd149 Jan 05 '16 at 17:35
  • should work, see https://jsfiddle.net/18ve6hzd/ maybe you don't load the locale files (from the doc: "If there is a locale file in moment-root/locale/ named after that key", key being "de" or "fr" here) –  Jan 05 '16 at 17:35
  • Chaning the require statement to this one will work: var moment = require('moment/min/moment-with-locales.js'); – delete Jan 05 '16 at 17:39

0 Answers0