Reputation: 14863
We are developing an internationalized web app and therefor use @angular/material-moment-adapter
to localize our dates. This works great, however we also want to display to our users how to they have to enter the Date.
So how can I get the value for a the en format (MM/DD/YYYY) but also the de format (DD.MM.YYYY).
I looked into the DateAdapter
but didn't find an option
Upvotes: 1
Views: 1041
Reputation: 31482
You can use localeData
and longDateFormat
to get locale specific format.
You can access the properties of the currently loaded locale through the
moment.localeData(key)
function. It returns the current locale or a locale with the given key.
function getFormatForLocale(localeCode){
return moment.localeData(localeCode).longDateFormat('L');
}
['en', 'de', 'fr', 'it'].forEach(code => {
console.log(`code ${code}: ${getFormatForLocale(code)}`);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
Upvotes: 3