2017-05-10 20 views
0

角度js中的日期變得像/ Date(1494288000000)/這是從asp.net對象列表中顯示的。來自Json列表的日期未能正確顯示在角度js中

<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> 
+2

提供json –

回答

0
var dateToDisplay = new Date(parseInt(jsonDate.substr(6))); 
return dateToDisplay; 

這是被包括在自定義過濾器的功能。

{{dateToDisplay | customFilterName | date}} 

這是在查看頁面中顯示日期。先通過自定義過濾器進行過濾,然後再通過日期過濾器進行過濾來源How do I format a Microsoft JSON date?

0

使用new Date ..角日期過濾器已包括new Date()轉換。我們不需要編寫額外的代碼。

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>

+0

這不適合我。 –

+0

這應該工作。試試這在plkr或fidle –