1

I am using Angular 8 date Pipe and manually set the LOCAL to 'en-GB'. But the output of the date pipe still is in the US format (mm/dd/yyyy). Any idea what's the issue? or Am I missing something?

const datePipe = new DatePipe('en-GB');
return datePipe.transform(value, 'short');
Sripter
  • 21
  • 4
  • 3
    "Only the en-US locale data comes with Angular. To localize dates in another language, you must import the corresponding locale data. See the I18n guide for more information." https://angular.io/api/common/DatePipe#description – enno.void Jul 15 '20 at 11:22

1 Answers1

3

You need to write the below code.

import { registerLocaleData } from '@angular/common';
import localeGB from '@angular/common/locales/en-GB';

registerLocaleData(localeGB, 'en-GB');

...

providers: [{ provide: LOCALE_ID, useValue: 'en-GB' }]
surendra kumar
  • 1,686
  • 11
  • 15