johnny04501
johnny04501

Reputation: 279

AngularJS date formatting

is any chance to format date in ng-repeat? I was trying to format it like

<div class="col-date">{{row.Calendar.start | date :  "dd.MM.y"}}</div>

But it was not working. How do I format date in ng-repeat?

Upvotes: 0

Views: 98

Answers (4)

keshav
keshav

Reputation: 46

try this it worked for me hope for you to

{{row.Calendar.start | date:'MMM-dd-yyyy'}}

Upvotes: 0

Aman Gupta
Aman Gupta

Reputation: 3797

Use moment and angular-moment, are definitely best modules out there for stuff related to dates.

First of all convert $scope.row.Calendar.start to date/moment object if it is a string and then use angular moment to show desired date format

Here is a how you can do so:

Inside controller:
$scope.row.Calendar.start = moment($scope.row.Calendar.start,'YYYY-MM-DD HH:mm:ss');

<div class="col-date">{{row.Calendar.start | amDateFormat : "dd.MM.y"}}

Upvotes: 1

Yogesh
Yogesh

Reputation: 1585

It seems like you are trying to apply angular date filter of a string object.

Try to first convert it to a Date object in controller and then apply date filter on it.

EXAMPLE

$scope.dtObj = new Date($scope.row.Calendar.start);

then in HTML write this

<div class="col-date">{{dtObj | date :  "dd.MM.y"}}</div>

for more details check out documentation here https://docs.angularjs.org/api/ng/filter/date

Upvotes: 0

Roman Hrokholskyi
Roman Hrokholskyi

Reputation: 61

From AngularJS perspective everything seems to be valid.

Please check following:

  1. Format of the data you provide to your date filter - is it UNIX timestamp or something else that might be processed by filter?
  2. Check if the data that you are trying to parse, is available

Please provide us with more information about what are you trying to convert, and what result do you have

Upvotes: 0

Related Questions