Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Datepicker change dateformat

i use the DatePicker from Angular Material and I would like to change the output format to yyyy/mm/dd.

Currently it prints the date in the following format: Wed Nov 14 2018 00:00:00 GMT+0100 (Central European Normal Time)

How can I do this?

datepicker = new FormControl('', [Validators.required]);


console.log(this.datepicker.value.toString());
like image 913
Robin Avatar asked Sep 15 '25 16:09

Robin


1 Answers

DatePicker works with date object. When you print on debugging console you will always see the date in full mode. If you want that your component shows the date in a specific format, you need to configure the library on the module.

@NgModule({
  providers: [
    {provide: MAT_DATE_LOCALE, useValue: 'en-GB'},
  ],
})
export class MyApp {}

More information are available on official documentation. I hope it helps.

like image 188
xcesco Avatar answered Sep 18 '25 10:09

xcesco