Search code examples
angulardatedate-pipe

How to validate date using DatePipe in Angular 5 app?


I have bsDatepicker with bsConfig and I'm trying to validate it, to make sure it is with the right format. The problem is that bsDatepicker create a date in a different format so I can't validate it.

The date string is:

Mon Apr 01 2019 19:05:36 GMT+1100 (Australian Eastern Daylight Time)

I'm trying to transform it using DatePipe like:

dateStr = this.datepipe.transform(date.toDateString(), 'MM/dd/yyyy');

What I'm getting is null. The expected result will be 04/01/2019. Any idea why the datepipe failed to transform? Thanks.


Solution

  • private static datePipeEn: DatePipe = new DatePipe('en-US');
    

    Solved my problem, I hope it will help someone with similar issue!