I want to customize it for my input fields and I can do it separately but it's not working when I put them together.
The first thing is I wanted to format is to set the calendars first day of the week from sunday to monday, I managed to do it with a custom adapter:
export class CustomDateAdapter extends NgxMatNativeDateAdapter {
getFirstDayOfWeek(): number {
return 1;
}
}
The second was to format the date time like this: 2021-04-21 8:00, and it works well with this code:
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
parse: {
dateInput: 'l, LT'
},
display: {
dateInput: 'YYYY-MM-DD HH:mm',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
}
};
The problem is if I use them together the date time format switches back to 2021/04/21 and time is missing, although the calendar starts with monday which is fine but the format is not. I can't figure it out why the date time format is not working after I use the custom calendar format. Any ideas?
The solution, which worked for me, was:
1/ Define a
CustomDateAdapter
and implement the methods:getFirstDayOfWeek
andformat
// Filename 'custom-date-adapter.ts'
2/ Then, within your module, use: