问题
Im trying to run a simple query like
Insert into table (somedate) values ('2018-06-11 23:59:00')
but Sequelize executes it as
Insert into table (somedate) values ('2018-06-12 02:59:00')
Is there an option to set the date "as is" without converting or changing it in any way?
回答1:
You can actually tell sequelize not to convert it to UTC while reading and you can also provide a time zone for while writing
const sequelize = new Sequelize('db_name', 'postgres', 'postgres', {
host: '127.0.0.1',
dialectOptions: {
useUTC: false //for reading from database
},
dialect: 'postgres',
timezone: '+05:30', // for writng
});
回答2:
I've found a hacky solution for you. You have to edit a Sequelize file which is not always an option, but it may solve your problem.
Open sequelize/lib/data-types.js and you will see
DATE.prototype._stringify = function _stringify(date, options) {
date = this._applyTimezone(date, options);
return date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
};
The Z in the date.format() function means "current time zone", try removing the Z :
return date.format('YYYY-MM-DD HH:mm:ss.SSS');
来源:https://stackoverflow.com/questions/50798083/node-sequelize-insert-date-as-is-without-converting-to-utc