Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs moment parse format

I have a ng-repeat that display the following expression

{{date}} // 2-1-2017

When I use angular-moment

{{date | amDateFormat:'DD'}} 

I got 1, which I'm expecting 2. how to make moment know my format is actually dd-mm-yyyy not mm-dd-yyy in the view? I don't want to parse it at my controllers level as it's complicated.

like image 442
Jessie Emerson Avatar asked Dec 30 '16 15:12

Jessie Emerson


1 Answers

According to the docs, AngularJs has a built-in filter for date which can be used with the following set:

{{ date_expression | date : format : timezone}}

So that you can use it like:

{{ date | date:'dd-MM-yyyy'}}

However if you use moment's date filter, it has to be a moment date (i.e., complete date with timezone defined) object and you can filter it in the same way that angular does.

{{ date | amDateFormat:'dd-MM-yyyy' }}
like image 113
lenilsondc Avatar answered Sep 20 '22 03:09

lenilsondc