0

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?

5
  • how your date looks like? Commented Jan 21, 2016 at 8:29
  • What is the problem here. What is value in row.Calendar.start Commented Jan 21, 2016 at 8:30
  • @Alexander so my date looks like : 2015-11-12 15:00:00 and if I use | date: "dd.MM.y" nothing happen Commented Jan 21, 2016 at 8:31
  • You can try with date in milliseconds, look docs.angularjs.org/api/ng/filter/date Commented Jan 21, 2016 at 8:32
  • if row.Calendar.start is a string object it won't work. date filter works on Date object. Commented Jan 21, 2016 at 8:33

4 Answers 4

1

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"}}

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

0

try this it worked for me hope for you to

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.