As you can see I have already changed the opening Date date-picker format bu, I want to change year built format to Year(YYYY) only while keeping other form fields intact. is it possible to do that? or any references.
1 Answer
Angular Material provides MAT_DATE_FORMATS object which is the collection of formats used by Datepicker to parse and display dates. To use custom date format we need to override MAT_DATE_FORMATS with the given formats. Import it and provide your own date format.
import { MAT_DATE_FORMATS } from '@angular/material';
Define a date format in a custom way as you require.
export const DATE_FORMAT= {
parse: {
dateInput: 'LL',
},
display: {
dateInput: 'DD MMM YYYY',
monthYearLabel: 'YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'YYYY',
},
};
In @Component, add the provider
providers: [
{ provide: MAT_DATE_FORMATS, useValue: DATE_FORMAT }
]
