I have question about date format in mongoDB, express and finally AngularJS. I tried to save user comment in mongoDB and next show in view. With comment body and comment author I have no problem but with comment date is. I save date using new Date()
, and in database I have usual date format. And now starts my problem, how display this date in more clear format e.g. yy/mm/dd (best solution will be 2 minutes ago or 1 year ago
). I tried use typical angular format date
but this no working. All time I get this format: 2017-09-05T12:13:08.611Z
. Look on my extract from code:
api (save in database)
product.comments.push({
body: req.body.comment,
author: user.username,
date: new Date(),
});
controller
.controller('seeMoreCtrl', function($scope, $routeParams, User, $location, $window){
var app = this;
User.readMoreCourse($routeParams.id).then(function(data){
if(data.data.success){
app.comments = data.data.product.comments;
} else {
$window.location.assign('/register');
}
});
})
html
<div ng-repeat="comment in seeMore.comments" class="all-users-comment-course">
<article class="one-comment">
<p class="user-name">{{ comment.author }}</p>
<p class="comment-date">{{ comment.date | date }}</p>
</article>
</div>
service
userFactory.readMoreCourse = function(id) {
return $http.get('/api/details/' + id)
}
schema
comments: [{
body: {
type: String,
trim: true,
},
author: {
type: String,
},
date: {
type: String
}
}]