我编写了一段代码,用于从数据库获取记录列表并将它们放入 $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);
});
}]);
然后,我想显示如下所示的记录。
<div ng-repeat="record in records">
<div>{{record.ID}}</div>
<div>{{record.SubmitDate}}</div>
<div>{{record.Status}}</div>
</div>
ID 和状态显示正确。但是,提交日期可能无法显示。提交日期在db中是“2016-08-30 09:59:17.080”,但所有提交日期在网站中显示时都变成“/Date(1472522357080)/”。
如何正确显示日期时间?谢谢。
最佳答案
尝试使用日期过滤器
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}
或
{{record.SubmitDate.replace('/Date(','').replace(')/','') | date:'yyyy-MM-dd HH:mm:ss Z'}}
关于Angularjs,如何在cshtml中显示日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39221487/