【发布时间】:2021-02-03 17:52:15
【问题描述】:
在 mongoose 中创建项目时,我试图将本地时间保存为默认时间
const ItemSchema = new mongoose.Schema({
item_name: { type: String, required: true },
shop_id: { type: mongoose.Schema.Types.ObjectId, ref: "Shop" },
createTime: { type: Date, default: moment().utcOffset(7) },
});
如您所见,我试图抵消moment UTC 时间,但它不起作用?我做错了什么?
【问题讨论】:
-
如果你只使用没有utcOffset的moment(),不能得到当地时间?因为这个函数返回从 UTC 的实际偏移量,通常使用 new Date() 到本地时间