Mysql
 sql >> Database >  >> RDS >> Mysql

Sequelize legge datetime solo in UTC

Puoi provare questo codice, ho avuto lo stesso problema e questo ha funzionato per me.

const sequelize = new Sequelize(mysql.database, mysql.user, mysql.password, {
    host: mysql.host,
    port:3306,
    dialect:'mysql',
    define: {
      underscored: true,
      freezeTableName: true, //use singular table name
      timestamps: false,  // I do not want timestamp fields by default
    },
    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: '+01:00'
});