我正在使用日期过滤器来格式化我的日期。但它只适用于日期。但是当我使用日期时间时它不起作用:
BOARD_SEPOLICY_DIRS += device/xxx/.../sepolicy/check_usb
目前此<tr class='clickable-row' ng-repeat="exam in examlist" ng-click="gotoProfile(exam.id)">
<td class="custom-icon-size" style="border-left: 0px solid #e0e0e0;">{{ $index + 1 }}</td>
<td class="custom-icon-size text-left">{{ exam.examtitle }}</td>
<td class="custom-icon-size">{{ exam.batchtitle }}</td>
<td class="custom-icon-size">{{ exam.standard }}</td>
<td class="custom-icon-size">{{ exam.examdate | date:"dd MMMM , yyyy" }}</td>
<td class="custom-icon-size">{{ exam.totalmarks }}</td>
<td class="custom-icon-size">{{ exam.status }}</td>
<td style="border-right: 0px solid #e0e0e0;">{{ exam.lastupdate | date:"dd MMM , yyyy hh:mm a" }}</td>
但{{ exam.examdate | date:"dd MMMM , yyyy" }}
保持不变。比如{{ exam.lastupdate | date:"dd MMM , yyyy hh:mm a" }}
谢谢
答案 0 :(得分:1)
如果日期是字符串,则需要将其转换为日期对象。创建一个将字符串日期转换为日期的函数
$scope.formatDate = function(date){
return new Date(date)
}
{{ formatDate(lastupdate) | date:"dd MMM , yyyy hh:mm a" }}
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.lastupdate = "2017-03-16 12:02:15";
$scope.formatDate = function(date){
return new Date(date)
}
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
{{ formatDate(lastupdate) | date:"dd MMM , yyyy hh:mm a" }}
</div>
&#13;