1

I am trying to filter the date using angular filter in HTML. But it is not working.

Here is my template code:

{{due_date | date:'MM/dd/yy'}}
  • The input is: {"due_date" : "2015-10-10 16:00:00.000+0000"}
  • The expected output is: 10/10/15

What mistake am I doing?

1
  • To help the community, your post was missing the current output (what error did you get, and what did the browser display instead of the expected result?). Commented Jan 25, 2016 at 17:27

3 Answers 3

2

It happens becouse due_date is a String instead of a Date object.

You can "convert" it by doing (maybe you should put this into your controller):

var due_date_parsed = new Date(due_date);
Sign up to request clarification or add additional context in comments.

1 Comment

if i parse the date "2015-12-16 22:00:12.844+0000" and use {{created_date_parsed | date:'hh:mm a'}} it is showing as 05:00 PM but it should be 10:00 PM.
0

parse your date like :

$scope.date = Date.parse(new Date());

in you code

Date.parse(jobDetails.trs_data.due_date)

Comments

0

if string is also in proper date format like '20140313T00:00:00' then this code will work perfectly fine. In other case you will have to convert/parse the string to date type.

1 Comment

if i parse the date "2015-12-16 22:00:12.844+0000" and use {{created_date_parsed | date:'hh:mm a'}} it is showing as 05:00 PM but it should be 10:00 PM.

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.