当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同 [英] NodeJS responded MySQL timezone is different when I fetch directly from MySQL

查看:52
本文介绍了当我直接从 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?

推荐答案

我在index.js初始化mysql连接时添加了timezone

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆