【发布时间】:2021-08-21 15:30:57
【问题描述】:
我正在使用 node 和 sequalize 来创建 Web API。一切正常,但是当我更新user 表如下:
var localDate=getDateTime();
console.log(localDate)
//output: 2021/06/03 18:01:22 this datetime is in local formate(GMT+0500),exactly which I need in `MySQL`
var data = { ActivationDate:localDate};
User.update(data, {where: { Email: req.body.email }}).then(num=>{/*whatever*/})
数据库更新了,但是在MySQLuser表的ActivationDate列是根据UTC更新的,也就是2021-06-03 13:01:22,我需要根据本地甲酸(GMT+0500) 2021/06/03 18:01:22.
为了防止这种行为,I also search from here, but these solutions are not working for me.
我还在 config.js 文件中添加了以下内容:
dialectOptions: {
useUTC: false, //for reading from database
dateStrings: true,
typeCast: function (field, next) { // for reading from database
if (field.type === 'DATETIME') {
return field.string()
}
return next()
},
},
timezone: '+05:00'
但是,ActivationDate 仍然按照 UTC 存储。
如何将我的本地日期时间保存在 ActivationDate 列中。
谢谢。
【问题讨论】:
标签: javascript mysql node.js datetime sequelize.js