Javascript 时区中的MongoDB日期
有没有办法将日期存储在本地时区而不是UTC 这是我的模式:Javascript 时区中的MongoDB日期,javascript,mongodb,date,Javascript,Mongodb,Date,有没有办法将日期存储在本地时区而不是UTC 这是我的模式: var WhispSchema = new mongoose.Schema({ text : String, pos : {latitude: Number, longitude: Number}, distance : {type : Number, default : 0}, created_by : {type : Schema.Types.ObjectId, ref : "UserSchema"}
var WhispSchema = new mongoose.Schema({
text : String,
pos : {latitude: Number, longitude: Number},
distance : {type : Number, default : 0},
created_by : {type : Schema.Types.ObjectId, ref : "UserSchema"},
upvote : {type : Number, default : 0},
downvote : {type : Number, default : 0}
});
WhispSchema.plugin(timestamps, {
createdAt: 'created_at',
updatedAt: 'updated_at'
});
但是字段“created_at”和“updated_at”是UTC格式的,我需要本地时区。否,MongoDB中用于存储日期的数据类型定义为UTC日期时间
但这确实是最好的,因为在其他时区存储日期时间可能会变得非常混乱。从数据库获取UTC时间戳后,最好根据需要将存储的UTC时间戳转换为本地时区
请参阅关于在聚合
管道中执行此操作的方法