Skip to content

timezone:'+08:00' not working! #7976

Closed
Closed

Description

@Symous

My mysql database using +8:00 time zone as defaule.

there is a table which contains a column called begintime( the type is timestamp in mysql),
and the index.js of the models is defined like this :

var sequelize = new Sequelize(conString,{
    define:{timestamp : false},
    timezone:'+08:00'
})

and when I trying to query 1 column of this table, it return "2017-06-22T16:00:00.000Z" but the stored value in database is '2017-06-23 00:00:00'.

it turned out the result is still 8 hours early than the correct time.

and I also have try to modify the timezone from +08:00 to +16:00, and the result changed to "2017-06-22T08:00:00.000Z" , which we can say that +16:00(or + 24:00) take affect but +08:00 not.

Activity

  1. tthos commented on Jul 24, 2017

    @tthos

    I had the same problem too.

    My timezone is '+07:00' and value in database is '2017-07-23 00:00:00'
    but i got '2017-07-22 17:00:00.000Z'

    var sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, timezone: '+07:00', })

    node 8.2.1
    mariadb 10.2.7
    sequelize 4.4.2

  2. andhikamaheva commented on Jul 27, 2017

    @andhikamaheva

    Happened with me too 😞

  3. zlcatwu commented on Aug 10, 2017

    @zlcatwu

    Same problem too.
    My database is using '+8:00' as timezone, and I got '2017-08-10T00:43:04.000Z' while the data in database is '2017-08-10 08:43:04' when setting timezone: '+08:00' in sequelize.
    Also, I got '2017-08-09T16:43:04.000Z' when setting without timezone.
    But the time is correct when creating no matter what the timezone is.

    • node v7.10.1
    • mariadb 10.2.7
    • sequelize 4.4.2
  4. samhoooo commented on Dec 6, 2018

    @samhoooo

    I am facing the same problem too.

    I am at +08:00 timezone.
    I inserted a timestamp field create_time by using new Date()
    I found that the time is saved as UTC timezone in my postgreSQL database.
    But, when I preform findAll() to the table,
    I found create_time is offset by -8 hours,
    e.g. 2018-12-06 02:40:06 is outputed as 2018-12-05T18:40:06.604Z

    Can I just get what my database is saving? i.e. UTC time

  5. uvzj commented on Dec 17, 2018

    @uvzj

    I am facing the same problem too.

    I am at +08:00 timezone.
    I inserted a timestamp field create_time by using new Date()
    I found that the time is saved as UTC timezone in my postgreSQL database.
    But, when I preform findAll() to the table,
    I found create_time is offset by -8 hours,
    e.g. 2018-12-06 02:40:06 is outputed as 2018-12-05T18:40:06.604Z

    Can I just get what my database is saving? i.e. UTC time

    i have the same problem

  6. caltonzhou commented on Dec 17, 2018

    @caltonzhou

    Maybe timezone is not needed if you use UTC.

    For example, my mysql server is timezone '+08:00',

    "mysql2": "^1.6.4",
    "sequelize": "^4.41.2"

    const sequelize = new Sequelize(database, username, password, {
        host: hostname,
        port: port,
        dialect: 'mysql',
        dialectOptions: {
            typeCast: function (field, next) {
                if (field.type == 'DATETIME' || field.type == 'TIMESTAMP') {
                    return new Date(field.string() + 'Z');
                }
                return next();
            }
        },
        operatorsAliases: false,
        pool: {
            max: 5,
            min: 0,
            acquire: 30000,
            idle: 10000
        }
    });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions