How to change angular material datepicker format

前端 未结 3 958
梦如初夏
梦如初夏 2020-12-06 00:40

This is the format of date I am getting when I am using angular material datepicker....Wed Nov 21 2018 00:00:00 GMT+0530 (India Standard Time)

But I nee

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 01:09

    import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material';
    import { MomentDateModule, MomentDateAdapter } from '@angular/material-moment-adapter';
    
     export const DateFormats = {
                parse: {
                    dateInput: ['YYYY-MM-DD']
                },
                display: {
                    dateInput: 'YYYY-MM-DD',
                    monthYearLabel: 'MMM YYYY',
                    dateA11yLabel: 'LL',
                    monthYearA11yLabel: 'MMMM YYYY',
                },
            };
    
        providers: [
    
            { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
              { provide: MAT_DATE_FORMATS, useValue: DateFormats }
    
          ],
    

    add above code in your app.module. it is working perfectly for me.

提交回复
热议问题