0

I want to convert this type of object to date format as (Sat 10/4/2016 5:03 PM) how can I do that of input type /Date(1487185200000)/ using angularJs

May json is something like this

[{
"Post_Id": 1,
"Posts_Date":/Date(1487185200000)/,
"Post_Description": "Test",

},
{
   "Post_Id": 2,
"Posts_Date": /Date(1487358000000)/,
"Post_Description": "Test",

}
]

This is my script in my controller

 $http.post("/Home/GetPostData").then(function (d) {
        $scope.Posts = d.data;
    });

And this is my View

 <div class="post_content" ng-repeat="p in Posts">
           <h3>  {{p.Post_Id}}</h3>
               {{p.Post_Description}}
                {{p.Posts_Date}} 

 </div>

And the output is somthing like this

1
Test
/Date(1487185200000)/
2
Test
/Date(1487358000000)/

want to convert my date as Standard format like (Sat 10/2/2016 4:50 PM) etc

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shaan
  • 1
  • 3

2 Answers2

0

You need to visit this Angular Date filter

html

{{p.Posts_Date|removeBaces| date: 'medium'}}

js

myApp.filter('removeBaces', function() {
  return function(input) {
        return input.replace('/Date(','').replace(')/','');
  }
});
amansinghgusain
  • 764
  • 5
  • 17
  • Yes but we are sending date as array in ng-repeat and there is a date parameter with each object in array so how can we change each parameter date in each object of Posts. – Shaan Feb 18 '17 at 11:00
0

If you are also interested in getting a Javascript Date (not just displaying), you can convert the JSON formmatted date/time information like this:

function parseJsonDate(jsonDateString){
    return new Date(parseInt(jsonDateString.replace('/Date(', '')));
}

Credit

Community
  • 1
  • 1
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
  • I just want to display date on view ... this method is not working in my case .. even it is not returning any thing.. will you please elaborate it more clearly?? – Shaan Feb 18 '17 at 11:01