【问题标题】:How can i change TimeZone when using timestamps in mongoose?在猫鼬中使用时间戳时如何更改时区?
【发布时间】:2019-06-14 11:17:44
【问题描述】:

如何更改猫鼬时间戳中的时区? 这里我有我的 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。 是否有可能做到这一点?如果可能的话,我该怎么做?谢谢。

【问题讨论】:

    标签: node.js rest mongoose timezone


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-10
      • 2017-09-04
      • 2014-07-14
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      相关资源
      最近更新 更多