How to change Mat-Datepicker date format to DD/MM/YYYY in simplest way?

后端 未结 9 1414
孤城傲影
孤城傲影 2021-02-07 09:00

I\'m setting up a mat-datepicker for DOB and traditionally the display format is MM/DD/YYYY,I need to change it to DD/MM/YYYY with less coding

I tried format tag in mat

9条回答
  •  情深已故
    2021-02-07 09:24

    I got it working after combining some knowledge from various answers here, so I thought I'd consolidate what worked for me.

    Angular 10:

    In your module, import MAT_DATE_LOCALE and add it to providers:

    import { MAT_DATE_LOCALE } from '@angular/material/core'
    
    @NgModule({
      declarations: [...],
      imports: [...],
      exports: [...],
      providers: [
        { provide: MAT_DATE_LOCALE, useValue: 'en-GB' }
      ]
    })
    

    If you use a shared module to import material this will change all the formats of your datepickers across the site.

提交回复
热议问题