我想显示类似 02-jan-2018
的日期格式获取方法
$scope.allReport = function() {
$http({
method: 'GET',
url: 'api/admin/report'
}).success( function (data) {
$scope.data = data.data;
console.log($scope.data);
}).error(function (response){
console.log("error");
});
}
回复
0:{
created_at:"2018-03-02 00:00:00"
cuid:21
id:64
name:"my"
status:"D"
time:"07:01 PM"
updated_at:"2018-03-02 00:00:00"
}
1:{
created_at:"2018-03-02 00:00:00"
cuid:22
id:65
name:"my1"
status:"P"
time:"06:59 PM"
updated_at:"2018-03-02 00:00:00"
}
我这样显示 查看
<tr ng-repeat="user in data | filter:{name:searchbyname}">
<td>{{$index+1}}</td>
<td>{{user.name}}</td>
<td>{{user.created_at | date : "dd-MMM-yyyy" }}</td>
<td>{{user.status}}</td>
</tr>
我希望在 02-jan-2018
中显示如created_at答案 0 :(得分:2)
试试这个,你得到字符串格式的日期。
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<table>
<tr ng-repeat="user in data | filter:{name:searchbyname}">
<td>{{$index+1}}</td>
<td>{{user.name}}</td>
<td>{{user.created_at | date : "dd-MMM-yyyy" }}</td>
<td>{{user.status}}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.data= [{
created_at: "2018-03-02 00:00:00",
cuid: 21,
id: 64,
name: "my",
status: "D",
time: "07:01 PM",
updated_at: "2018-03-02 00:00:00",
}, {
created_at: "2018-03-02 00:00:00",
cuid: 22,
id: 65,
name: "my1",
status: "P",
time: "06:59 PM",
updated_at: "2018-03-02 00:00:00"
}];
$scope.data = $scope.data.map(obj =>{
obj.created_at = new Date(obj.created_at); // converting string to date
return obj;
})
});
</script>
</body>
</html>
答案 1 :(得分:0)
建议形成朋友PLZ使用时刻你会遇到很多日期管道问题,角度和时刻更灵活;)
Angular2 date pipe does not work in IE 11 and edge 13/14
date pipe issue on IE10 - 'Intl' is undefined
https://www.npmjs.com/package/moment
{{now | momentPipe:'DD-MMM-YYYY'}}