The datepicker function works well unless I manually type in the date. When I input a date between 01.MM.YYYY and 12.MM.YYYY, the value switches to MM.DD.YYYY. However, if I input 16.09.2021 for example, it remains as DD.MM.YYYY.
Is there a way to change the date format from the input field?
HTML
<div class="form-group inline datepicker">
<mat-form-field appearance="fill">
<input matInput
[matDatepicker]="validFromPicker"
[formControl]="validFromFormControl"
(dateChange)="setValidFromDate($event.value)">
<mat-datepicker-toggle matSuffix [for]="validFromPicker"></mat-datepicker-toggle>
<mat-datepicker #validFromPicker></mat-datepicker>
</mat-form-field>
</div>
TypeScript
validFrom: Date;
validFromFormControl: FormControl;
ngOnInit() {
this.validFromFormControl = new FormControl(new Date());
this.validFrom = new Date();
}
setValidFromDate($event: any) {
this.validFrom = $event;
}
I attempted to adjust the locale in AppModule following advice from this thread - , but unfortunately, it did not work as expected.