我使用 swampdragon 编写了一个通知应用程序。不幸的是, pub_date 变量包括我不希望它存在的微秒。如何在管理站点(上午版本)中将其格式化为 'dd-MM-yyyy HH:mm:ss' 或类似的格式?我的控制器.js:
var AnnounceControllers = angular.module('AnnounceControllers', []);
AnnounceControllers.controller('AnnounceListCtrl', ['$scope', '$dragon', function ($scope, $dragon) {
$scope.announceList = {};
$scope.announcements = [];
$scope.channel = 'announce';
$dragon.onReady(function() {
$dragon.subscribe('announcements', $scope.channel, {announce_list__id: 1}).then(function(response) {
$scope.dataMapper = new DataMapper(response.data);
});
$dragon.getSingle('announce-list', {id:1}).then(function(response) {
$scope.announceList = response.data;
});
$dragon.getList('announcements', {list_id:1}).then(function(response) {
$scope.announcements = response.data;
});
});
$dragon.onChannelMessage(function(channels, message) {
if (indexOf.call(channels, $scope.channel) > -1) {
$scope.$apply(function() {
$scope.dataMapper.mapData($scope.announcements, message);
});
}
});
}]);
我的 app.js:
var AnnounceApp = angular.module('AnnounceApp', [
'SwampDragonServices',
'AnnounceControllers'
]);
在 HTML 中:
<h3 ng-repeat="item in announcements">
<div class="alert alert-info" role="alert">
{{ item.content }} {{item.pub_date| date:'dd-MM-yyyy HH:mm:ss'}}
<br>
</div>
</h3>
模型.py:
pub_date = models.DateTimeField(auto_now_add = True)
序列化程序.py:
class AnnounceSerializer(ModelSerializer):
class Meta:
model = "post.Announce"
publish_fields = ("content","pub_date")