我正在尝试使用 AngularJS 从 MongoDB 检索时间数据。
棘手的部分是我使用 MongoJS 时没有时间数据的模式,因此我无法直接查询它。每当我从数据库中提取数据时,我都会以以下格式接收数据:
2017-06-29T23:00:00.000Z
我的主要问题是我不使用架构来设置数据的特定格式,我希望它显示在:
日/月/年
这是我用于整体数据输入、获取、删除和编辑的 NodeJS 代码:
app.post('/posts', function(req,res){
dbc.posts.insert(req.body, function(err, doc){
res.json(doc);
})
});
app.delete('/posts/:id', function(req,res){
var id = req.params.id;
console.log(id);
dbc.posts.remove({_id: mongojs.ObjectId(id)}, function(err, doc){
res.json(doc);
})
});
app.get('/posts/:id', function(req,res){
var id = req.params.id;
console.log(id);
dbc.posts.findOne({_id: mongojs.ObjectId(id)}, function(err, doc){
res.json(doc);
});
});
app.put('/posts/:id', function(req, res){
var id = req.params.id;
console.log(req.body.system);
dbc.posts.findAndModify({query:{_id:mongojs.ObjectId(id)},
update: {$set: {issue: req.body.issue, system: req.body.system, date: req.body.date, priority: req.body.priority, description: req.body.description, status: req.body.status}},
new:true}, function(err, doc){
res.json(doc);
console.log(req.body.date);
});
});
我如何在AngularJS控制器中过滤我的数据以我想要的格式显示它,因为我没有为数据库使用特定的模式?
angularjs 默认提供了一个时间过滤器。你可以直接使用
{{ date_expression | date : format : timezone}}
在这里阅读文档
您可以更改此设置以满足您的需要。
{{date_expression| date:'dd MMM, yyyy '}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句