当我直接从MySQL获取数据时,NodeJS响应的MySQL时区有所不同 [英] NodeJS responded MySQL timezone is different when I fetch directly from MySQL
本文介绍了当我直接从MySQL获取数据时,NodeJS响应的MySQL时区有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我直接请求MySQL时,我以UTC取回日期(我在MySQL服务器中设置了UTC),但是使用NodeJS却获得了UTC + 2本地时区数据,为什么?如何设置NodeJS以获取UTC?
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?
推荐答案
我在初始化mysql连接时在index.js中添加了时区
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
};
这篇关于当我直接从MySQL获取数据时,NodeJS响应的MySQL时区有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文