2
    <mat-form-field>
    <input matInput name=""       
     [matDatepicker]="myDatepicker"  
      [max]="maxDate"                                                                                                        
        placeholder="Select Date Of Birth"                                                                   
         id="dateOfBirth"                                                                   
          [value]="value"                                                                    
           onkeydown="return false" />                                                             
<mat-datepicker-toggle matSuffix [for]="myDatepicker"></mat-datepicker-toggle>
    <mat-datepicker #myDatepicker mat-open-on-focus></mat-datepicker>
    </mat-form-field>

This is my snippet which is implemented for two-way binding.

Value return JS date object output as follow 

Current output:
"Mon Jan 01 1900 00:00:00 GMT+0530 (India Standard Time)"

Required Output:
01/01/1990 (MM/DD/YYYY).

I have refer following links, but did not get expected output - Angular 2 Material 2 datepicker date format

  • I use momentjs for this https://momentjs.com/ – Swoox Nov 30 '17 at 14:52
  • Yes, 1) we can use moment to get output as "date string". 2) 2nd way to get date string "toLocaleDateString()". But as of now i am using Angular material (matDatePicker) which required Date Object to bind value, If we provide string to bind, It shows an error:- Error: Datepicker: Value must be either a date object recognized by the DateAdapter or an ISO 8601 string. Instead got: 12/31/1899 – mangeshbhuskute Dec 01 '17 at 04:29
  • Well how does your date look like when you receive it? – AT82 Dec 01 '17 at 17:32
  • It's a string "mm/dd/yyyy" – mangeshbhuskute Dec 01 '17 at 17:41
  • Well if it looks like that your datepicker should work just fine and display the correct format that you wish. Please make demo to showcase your issue :) – AT82 Dec 01 '17 at 17:57
  • Thanks for your guidance. We have use material way to display the required formatted date. – mangeshbhuskute Nov 24 '18 at 06:23

0 Answers0