NodeJS responded MySQL timezone is different when I fetch directly from MySQL
When I request MySQL directly, I get back date in UTC (I set UTC in MySQL server), but with NodeJS I get UTC+2 local time zone data, why? How can I set NodeJS to get UTC?
I have added timezone in index.js when initializing mysql connection
var db_config = {
host : 'localhost',
user : 'xxx',
password : '',
database : 'xxx',
timezone: 'utc' //<-here this line was missing
};
Although this is an old question, I had a similar problem and adding the config timezone: 'utc'
did not solve the problem (it get worse).
The solution I finally used is to add the config dateStrings : true
such that I have a raw string date and mysql module does not do itself the conversion to a javascript date.
Then I use moment.utc(thedatestring) to obtain a suitable javascript object (in the database, I save all dates as UTC in DATETIME columns, independently of the configuration of the host). Using Moment.js.
Try setting the timezone value to "UTC+0", that worked for me.