0

I am getting the

 last_login:"Thu, 09 Oct 2014 16:59:12 +0530" ,

In JSON data and I want to display it like "Oct,09". How to achieve this in AngularJS?

Can we do this using date filter ?
If Yes then how?

0

2 Answers 2

2

Can we do this using date filter ?

You can use date-filter like

In HTML Template Binding

{{ dateVariable| date : "MMM, dd"}}

In JavaScript

$filter('date')(dateVariable, "MMM, dd", timezone)
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your solution. but I am getting the value in string. Does your first solution work even if any kind of value is coming like string?
@ShivekParmar, You can simply convert your string variable to date like new Date(last_login), Then above will surely work.
does your second solution work if I use it inside html or I have to use it inside controller.?
@ShivekParmar, Seconds should be used in Controller not inside HTML.
2

create a custom filter

app.filter('dateToISO', function() {
  return function(input) {
    input = new Date(input).toISOString();
    return input;
 };

call that custome filter to get the date in ISO format and format into desire format angular api for date

<div>
    {{"Thu, 09 Oct 2014 16:59:12 +0530" | dateToISO | date:'MMM, yyyy'}}  // filter date using
</div> 

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.