0

The date in angular js is getting displayed like /Date(1494288000000)/ which is from asp.net list of objects.

<tr class="unread" data-ng-repeat="notification in Notifications | filter:q | startFrom:currentPage*pageSize | limitTo:pageSize">
    <td class="inbox-small-cells">
        <input data-ng-model="arr[notification.NotificationId]" type="checkbox" value="{{notification.NotificationId}}" ng-checked="" ng-click="" class="mail-checkbox">
    </td>         
    <td class="view-message  dont-show">{{notification.Title}}</td>
    <td class="view-message ">{{notification.Message}}</td>
    <td class="view-message  text-right">{{notification.Date | date}}</td>
</tr>
Prerak Sola
  • 9,517
  • 7
  • 36
  • 67
Sachin G
  • 29
  • 2

2 Answers2

0

Use new Date.. Angular date filter have included new Date() conversion. We don't need to write extra code.

angular.module('exApp',[])
       .controller('mainController', function ($scope) {
          $scope.current = new Date();
          var d = 1494288000000; // number
          console.log(typeof d);
          $scope.ex ="1494288000000"; // string 
          console.log(typeof $scope.ex);
          $scope.me = Date($scope.ex);
          $scope.newDate = new Date(d);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="exApp">
  <div ng-controller="mainController">
      {{ current | date: 'd-MM-y'}} <br>
   Converted :  {{newDate|date}} <br>Without Convert : {{ex|date}}<br>Extra convert: {{me|date}}
  </div>
</div>
Manikandan Velayutham
  • 2,228
  • 1
  • 15
  • 22
0
 var dateToDisplay = new Date(parseInt(jsonDate.substr(6))); 
 return dateToDisplay;

This is to be included in the custom filter function.

  {{dateToDisplay | customFilterName | date}}

This is to display date in view page. First filter through custom filter and then again filter through date filter. Source How do I format a Microsoft JSON date?

Community
  • 1
  • 1
Sachin G
  • 29
  • 2