0

How to display date in angular with filter.

Below output shows the input and the output (with/without angular date filter)

In: {{v.Dt}}  
Angular: {{v.Dt | date:'yyyy-MM-dd HH:mm:ss Z'}}
prints:

In: 2015-03-19T05:52:10.634062Z 
Angular: 2015-03-19T05:52:10.634062Z 

The desired display format is 19 Mar 2015

Any help is appreciated.

2 Answers 2

2

I also had similar problem and then I came across this solution:

Add this into your app.js file

angular.module('AngularAuthApp').filter('Convertdate', function ($filter) {
    return function (input) {
        if (input == null) { return ""; }
        var _date = $filter('date')(new Date(input), 'dd MMM yyyy');
        return _date.toUpperCase();
    };
});

And then call like this

   <small class="styleColor">{{Event.EventStartDate | Convertdate}}</small>

EventStartDate is your datefield

You also can change the format of date in this

var _date = $filter('date')(new Date(input), 'dd MMM yyyy');
                                                 ^^ here

To mention that angularauthapp is your app name

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

Comments

1

You can do it in the markup

{{v.Dt | date : 'dd MMM 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.