moment.js: convert timestamp and show month in German

2.3k views Asked by At

I have troubles displaying the month of the following operation in German:

var date = moment.unix(valueTimestamp).format("DD. MMMM YYYY");

I have tried the following, but it does NOT work:

// Attempt #1:
var date = moment.lang('de').unix(valueTimestamp).format("DD. MMMM YYYY");
// Attempt #2:
var date = moment.local('de').unix(valueTimestamp).format("DD. MMMM YYYY");

How do I achieve that the month name will be German?

EDIT

I included the locales.js file and create a js fiddle which will demonstrate my problem:

https://jsfiddle.net/e3a7bgLu/

The console displays the following error:

Uncaught TypeError: moment.locale(...).unix is not a function
2

There are 2 answers

0
Pogrindis On BEST ANSWER

You have the unix constructor AFTER you are defining a locale.. So you're defining a locale onto nothing.

You need to create the moment first before defining a locale.

So moment will be created from the .unix() method, and from this returned result, you can define a locale onto it.

moment.unix(1414543560).locale('de').format("DD. MMMM YYYY");

Should do the trick! :)

JSFiddle

0
Pataar On

I've updated the fiddle you posted. Should work this way. https://jsfiddle.net/e3a7bgLu/2/

So first call moment.locale and then call the moment.unix function.