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?
推荐答案
我在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 时区不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01