Angularjs, how to display DateTime in cshtml

2019-02-28 10:26发布

I wrote a piece of code for getting a list of record from db and put them in $scope.records.

var app = angular.module('MyApp', []);
app.controller('MyAppController', ['$scope', '$http', function ($scope, $http) {
    $http({ method: 'GET', url: '/Api/GetRecord' }).
           success(function (data, status, headers, config) {
               $scope.records = data;
           }).
           error(function (data, status, headers, config) {
               alert(data);
           });
}]);

Then, I want to display the records like below.

<div ng-repeat="record in records">
   <div>{{record.ID}}</div>
   <div>{{record.SubmitDate}}</div>
   <div>{{record.Status}}</div>
</div>

The ID and status are shown correctly. However, the submit dates cannot show probably.The submit date is "2016-08-30 09:59:17.080" in db but all the submit dates become "/Date(1472522357080)/" while displaying in the website.

How can I display the datetime correctly? Thanks.

2条回答
▲ chillily
2楼-- · 2019-02-28 10:57

Try the new Date function as $scope.date = new Date (1472522357080); and bind the same $scope.date variable as ng-model to the date control.

查看更多
欢心
3楼-- · 2019-02-28 11:02

try with date filter

{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}

or

{{record.SubmitDate.replace('/Date(','').replace(')/','') | date:'yyyy-MM-dd HH:mm:ss Z'}}
查看更多
登录 后发表回答