I created a table with timestamps using sequelize. when I am updating the table, it automatically updates the timestamp (i.e createdAt and updatedAt). but these times are different from my local time. I have attached herewith 2 screenshots with the model script if I use moment to convert timezone like this useupdateddAt: moment().utc(new Date())
it works fine. is there a way to automatically update the timestamps with current timezone?
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('States', {
hashCode: {
type: Sequelize.STRING,
unique:true,
autoIncrement:false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('States');
}
};
timezone: The timezone configured on the MySQL server. This is used to type cast server date/time values to JavaScript Date object and vice versa. This can be 'local', 'Z', or an offset in the form +HH:MM or -HH:MM. (Default: 'local')
So your answer points to the correct attribute to set but the value will cause an error, at least in v6 and onwards, using+00:00
has done the trick for me npmjs.com/package/mysql#connection-options – Faerie