Search code examples
angularjsdateangularjs-scopeangular-filtersng-bind

How to format a date in AngularJS (Datefilter)


I need to format a date with the AngularJS date-filter. Unformatted the date looks like this:

2017-03-02T00:00:00.000Z

What I want to achieve:

03/02/2017

I use the date-filter like this:

<p data-ng-bind="selectedEvent.start" | date:'MM/dd/yyyy'>{{selectedEvent.start}}</p>

And this is what I get:

Thu Mar 02 2017 00:00:00 GMT+0000

What am I doing wrong?


Solution

  • You're right and wrong.

    <p data-ng-bind="selectedEvent.start | date: 'MM/dd/yyyy'"></p>
    

    You were binding the date, but then had the filtering outside the quote. Then you had the double braces inside the

    too, which was a duplicate.