在猫鼬中使用时间戳时,如何更改TimeZone?

时间:2019-01-21 04:49:29

标签: node.js rest mongoose timezone

如何更改猫鼬时间戳中的时区? 这里我有我的jobSchema:

model.js:

const jobSchema = new Schema({
  owner: {
   type: Schema.ObjectId,
   ref: 'User',
   required: true
 },
 title: {
  type: String
 },
 description: {
  type: String
 },
 tag: {
  type: String
 },
 ....
 }, {
  timestamps: true,
  toJSON: {
   virtuals: true,
   transform: (obj, ret) => { delete ret._id }
  },
  toObject: { virtuals: true }
 }) 

时间的结果是:

"createdAt": "2019-01-21T04:35:20.076Z"

但是我的实际时间是上午11.35。

我想将时间戳TimeZone更改为GMT / UTC +7。 是否有可能做到这一点?如果可能,我该怎么办?谢谢。

1 个答案:

答案 0 :(得分:0)

MongoDB始终以UTC格式存储日期。但是,您可以自己将其转换为您的时区,也可以mongoose-timezone将其转换为本地时区的日期。

相关问题