0

I have an date in format /Date(1451602800000)/.

I would like to show this date in 'short' format.

I tried {{myDate | date:'short'}} but the result is /Date(1451602800000)/

1

2 Answers 2

1

here is another approach.
I use the RegExp from @sachila ranawaka
in js:

.filter('regexp', function(){
    return function(input){
        return input.match(/\/Date\(([0-9]*)\)\//)[1];
    };
});

in html:

{{ myDate | regexp | date:'short' }}

this way you can use angular date filter on your preference.

ref: https://docs.angularjs.org/api/ng/filter/date

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

Comments

0

Use a custome filter like this

angular.module("app",[])
.controller("ctrl",function($scope){
	$scope.date = "\/Date(1451602800000)\/";
})
.filter("mydate", function() {
    var re = /\/Date\(([0-9]*)\)\//;
    return function(x) {
        var m = x.match(re);
        if( m ) return new Date(parseInt(m[1]));
        else return null;
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  {{date |mydate  }} <br>
  {{date |mydate | date: 'yyyy-MM-dd HH:mm' }}
</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.