如何更改猫鼬的日期时区?
问题描述:
在模型模式中,
使用
updated: {
type: Date,
default: Date.now
在server.js中
In server.js
put(function(req, res) {
var query = {name: req.params.name};
// use our bear model to find the bear we want
Domain.find(query, function(err, domains) {
if (err)
res.send(err);
var domain = domains[0];
domain.password = req.body.password; // update the bears info
domain.updated = new Date();
// save the bear
domain.save(function(err, data) {
if (err)
res.send(err);
res.json({ status: 'success', message: 'domain updated!' }, data);
});
});
});
但是,
在数据库端显示,
"updated": "2016-02-27T16:20:42.941Z"
但是,我的时区是UTC + 02.00
But, my timezone is UTC+02.00
所以应该像18:20:42
So it should be like 18:20:42
我做错了什么?
答
我正在使用矩时区
npm install moment-timezone
const moment = require('moment-timezone');
const dateThailand = moment.tz(Date.now(), "Asia/Bangkok");
console.log(dateThailand); // "2018-08-20T16:35:14.033+07:00"
*** Asia/Bangkok +07:00
猫鼬中的架构.
const categorySchema = new Schema(
{
_id: {type: mongoose.Schema.Types.ObjectId, auto: true},
c_name: String,
created_by: String,
created_date: {type: Date, default: dateThailand},
updated_by: String,
updated_date: {type: Date, default: dateThailand}
}, {_id: false}
);
查看created_date, updated_date: {type: Date, default: dateThailand }
了解详情: http://momentjs.com/timezone/docs/
*如果您使用的是Robo 3T工具.
您可以设置显示日期在..."
You can set "Display Dates In..."
Options > Display Dates In... > Local Timezone
:)为我工作.