Make sure to specify your preferred 'locale':
- In your app.module.ts:
// Include all necessary languages (e.g., '../locales/en-GB', '/locales/en-US', ... ).
// For this instance, I will incorporate 'es' for Spanish and 'fr' for French:
import myLocaleEs from '@angular/common/locales/es'
import myLocaleFr from '@angular/common/locales/fr'
import {registerLocaleData} from '@angular/common';
registerLocaleData(myLocaleEs);
registerLocaleData(myLocaleFr);
- In your HTML:
// 'en' is the default language, no need to register
{{ fecha | date: "long":"":"en" }}
{{ fecha | date: "long":"":"es" }}
{{ fecha | date: "short":"":"fr" }}
or {{ fecha | date: 'MMM d, y':"":"fr" }}
Setting Globally
This method establishes your desired locale globally (if different from the default 'en'), eliminating the need to specify it in every pipe usage:
In addition to the aforementioned code, remember to include the following import and PROVIDERS section in app.module.ts:
...
import { LOCALE_ID} from '@angular/core';
...
...
providers: [
{provide: LOCALE_ID, useValue: 'es'} // Use the same value as above for βesβ or 'fr' or any other registered locale
],
...