I'm trying to parse the String using momentjs:
let date = "19. Juli 2016 05:00";
The string contains the month of july written in german and it has the "LLL" format according to the momentjs doc.
When I try to parse it with
moment(date,'LLL');
I get a wrong date.
When I try to parse it with
moment(date,'LLL','de');
I get the error message:
TypeError: config._locale is null.
How can I correctly parse this string?
You should use corresponding moment-locales
dependency to be able to recognize dates in other languages. You can find the list of locales here and use it from the CDN, or download and bundle it yourself from momentjs (get the one that says moment-with-locales.js
)
And in that case use the following parse method (as you've tried it already):
let momentObj = moment(DATE_STRING, FORMAT, LOCALE);
let momentObj = moment("04. Juli 2016 05:00", 'LLL', 'de');
console.log(momentObj);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/locale/de.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With