Moment.js停留在“几秒钟前”

时间:2018-09-02 21:51:45

标签: node.js express momentjs

我最近将应用程序部署到了Heroku;但是,提交评论或帖子后,Moment.js似乎总是在几秒钟前返回

这是app.js文件中的相关代码:

var moment = require('moment');
app.locals.moment = require('moment');

这些是相关的架构:

var postSchema = new mongoose.Schema({
    title: String,
    description: String,
    author: {
        id: {
            createdAt: {type:Date, default: Date.now},
            type: mongoose.Schema.Types.ObjectId,
            ref: "User"
        },
        username: String
    },  
    comments:[
        {
            type: mongoose.Schema.Types.ObjectId,
            ref: "Comment"
        }
    ]
});



var commentSchema = mongoose.Schema({
    text: String,
    author: {
        id:{
            createdAt: {type:Date, default:Date.now},
            type: mongoose.Schema.Types.ObjectId,
            ref: "User"
        },
        username: String
    }
});

这是相关的EJS代码:

<%= moment(comment.createdAt).fromNow() %>

由于在我的模式中,我已定义createdAt为现在的日期,所以时间应该正确输出吗? 任何帮助将不胜感激,谢谢!

0 个答案:

没有答案