Angular 2 Material 2 datepicker date format

前端 未结 14 2270
悲哀的现实
悲哀的现实 2020-11-28 23:21

I need help. I don\'t know how to change the date format of the material 2 datepicker. I\'ve read documentation but I don\'t understand what I actually need to do. Output da

14条回答
  •  [愿得一人]
    2020-11-28 23:46

    Create a constant for date format.

    export const DateFormat = {
    parse: {
      dateInput: 'input',
      },
      display: {
      dateInput: 'DD-MMM-YYYY',
      monthYearLabel: 'MMMM YYYY',
      dateA11yLabel: 'MM/DD/YYYY',
      monthYearA11yLabel: 'MMMM YYYY',
      }
    };
    

    And Use the below code inside app module

     providers: [
      { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
      { provide: MAT_DATE_FORMATS, useValue: DateFormat }
    ]
    

提交回复
热议问题