1

I have a JSON file returning a number of dates in such format:

/Date(1235548800000)/

How can i filter this in my Controller to only return the year?

I have tried:

 var filteredDate = $filter('date')($scope.ToDate, 'yyyy');

 console.log(filteredDate);

But console is displaying:

/Date(1235548800000)/
3
  • What date format is that? Commented Jul 29, 2014 at 11:15
  • @JMK - docs.angularjs.org/api/ng/filter/date Commented Jul 29, 2014 at 11:17
  • @JMK - In my HTML if i do {[{ filteredDate .substring(6, filteredDate .length - 2) | date:'yyyy' }]} The output is Nov 2009 Commented Jul 29, 2014 at 11:18

3 Answers 3

1

You could try this

var parsedDate = new Date(parseInt($scope.ToDate.substr(6)));
var filteredDate = $filter('date')(parsedDate, 'yyyy');
Sign up to request clarification or add additional context in comments.

Comments

0

Check my Plunker. You should get the timestamp from ToDate string. You can use something like this if all the time date has the same format.

var dt=$scope.toDate.substring($scope.toDate.indexOf("(")+1,$scope.toDate.indexOf(")"));

Comments

0

Try this:

var filteredDate = YourDate.getFullYear();
console.log(filteredDate);

Hope it helps...........!

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.