how to format the output value of an angular material DatePicker when submitting the form?

Viewed 53

I am using angular 12 with a form containing a material DatePicker. Here is the relevant part of my component's html.

<mat-form-field>                
    <input formControlName="dateOfBirth" matInput [matDatepicker]="picker" placeholder="Date Of Birth">
    <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
    <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

When I submit my form, I get the following value for dateOfBirth field:

Date Tue Dec 14 2021 00:00:00 GMT+0100 (Central European Standard Time)

Instead of this output, I would like an output of the form e.g. DD-MM-YYYY. Obviously, I could format this value afterwards but I was wondering if this could be done during the submit mechanism. Would you know how to do this ?

0 Answers
Related