Search code examples
angulardate-pipe

Angular Date pipe month value wrong


I have the following code in my template:

<div>{{createdOn | date:'yyyy-mm-dd'}}</div>

The value of createdOn is 1565762489936 in milliseconds. In terms of date it is 'Wed 14 August 2019'.

Instead I get '2019-31-14'. The month value is wrong.

Whats the issue here?


Solution

  • When using Angular’s Date Pipe you need to keep its custom format options in mind:

    Lowercase mm will print the minute with two digits.

    What you should use instead is uppercase MM which represents the month:

    <div>{{createdOn | date:'yyyy-MM-dd'}}</div>