node.js - 在猫鼬中使用时间戳时如何更改时区?
问题描述
如何更改猫鼬时间戳中的时区?这里我有我的jobSchema:
模型.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。是否有可能做到这一点?如果可能的话,我该怎么做?谢谢。
解决方案
MongoDB 始终以 UTC 格式存储日期。但是,您可以自己将其转换为您的时区或mongoose-timezone以转换本地时区的日期。
推荐阅读
- android - Android,重用不是布局,而是通过 XML 重用视图
- next.js - 在 NEXTJS 的 getServerSideProps() 中获取一些 html 表单数据(或对象)
- r - 用于查看 df 的元素是否包含在 List 内的 df 中的逻辑向量
- mysql - MySQL:仅匹配键字符串表中字符串中的精确字符串
- react-native - 如何将文本组件作为参数传递到我的函数中以确定按下了哪个元素?
- c# - 如何通过特定源 C# 获取 Windows 事件日志列表
- angular - 为角度反应形式添加自定义验证时出错
- c - 该程序是否正确计算 CRC?
- python - 从 Pandas groupby 对象中收集系列
- typescript - connect-redis.redis 和 ioredis.redis 类型不兼容