gpt4 book ai didi

MySql 在选择记录时更改日期

转载 作者:行者123 更新时间:2023-11-29 17:01:06 27 4
gpt4 key购买 nike

我正在使用带有 NodeJs 的sequelize ORM。当我将值传递给 where 子句中的 DateTime 列时,它会自动添加本地偏移量。

例如我正在写这个。

TripDetail.findOne({
where: {
trip_detail_id: trip_id,
trip_detail_trip_start: '2017-10-05 15:27:38'
},
})

它显示的查询是日志是

SELECT * 
FROM `tbl_trip_detail` AS `TripDetail`
WHERE `TripDetail`.`trip_detail_id` = 1
AND
`TripDetail`.`trip_detail_trip_start` = '2017-10-05 22:27:38'

我的sequelize配置是

{
user: 'root',
password: '',
database: 'abc',
dialect: 'mysql',
options: {
dialect: 'mysql',
host: 'localhost',
port: 3306,
logging: console.log, // or specify sails log level to use ('info', 'warn', 'verbose', etc)
dialectOptions: {
timezone: 'utc', //for reading from database
dateStrings: true,
typeCast: function (field, next) { // for reading from database
if (field.type === 'DATETIME') {
return field.string()
}
return next()
}
},
},

}

我还尝试完全删除 dialectOptions 对象。

最佳答案

您应该在 Sequelize 配置中设置正确的时区像:

 timezone: '+08:00'

这取决于您所在的时区

关于MySql 在选择记录时更改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52257453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com