简体   繁体   中英

moment.js date to timestamp internationalization (german)

I could not find a similar question so here it goes: Moment.js does not seem to understand months in other language than english when doing the formmating.

Moment.js with locales is in the assets and when I try following:

moment('1. März 2014').format('LLLL');
"Invalid date"

on the other hand this works:

moment('1. March 2014').format('LLLL');
"Samstag, 1. März 2014 00:00 Uhr"

I already have some workarounds but it would be awesome to make it clean. Any ideas what an U diubg wrong?

I use chrome 38.0.2125.111 and moment.js 2.8.3.

Please tell me if you need more info about the problem.

EDIT

It looks like only some months are problematic. This works perfectly:

moment('1. Januar 2014').format('LLLL');
"Mittwoch, 1. Januar 2014 00:00 

I thought it might be special chars like ä in März. But this won't work neither:

moment('1. Dezember 2014').format('LLLL');
"Invalid date"

Set the locale to german explicitly and provide the format of the input

moment.locale("de"); moment('1. März 2014', "DD. MMMM YYYY").format("LLLL"));

Works for me: http://jsfiddle.net/sbbg3dzt/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM