(not
. Is there a way to do so in a simple way?DatePipe
In my Angular 8 app, I can't manage to display date fields in a localized form. I'd like to come up with something like the following: in English : "February 18, 2020 12:15:50" in French : "18 ...
angular provides a lot of locales, so use can register right locale which will be used in date pipe.ngx-translate
Then you can specify locale in date pipeAngular i18n
or overried default localeTranslateService#currentLang
UPDATEDatePipe
Angular i18n uses differential builds, but ngx-translate fetches needed locale on demand. As we can not combine those approaches, we can create custom date pipe, which would meet our requirements.
// app.module.ts
import { registerLocaleData } from '@angular/common';
import frenchLocale from '@angular/common/locales/fr';
import { LOCALE_ID, NgModule } from '@angular/core';
registerLocaleData(frenchLocale);
someDate | date: null: null: 'fr'
Yes, you can use
@NgModule({
providers: [
{ provide: LOCALE_ID, useValue: "fr" }
]
})
DatePipe
. As you can see, it use
token be default. If you use Angular CLI, LOCALE_ID is provided automatically: A locale code for the locale format rules to use. When not supplied, uses the value of LOCALE_ID, which is en-US by default
英文:"February 18, 2020 12: 15: 50"法语:"18 février 2020, 12:15:50"我想我应该使用Angular的 LOCALE_ID
:
{{ myDate