2017-05-25 24 views
0

在我的节点应用程序中,我有MySQL DB,它具有格式为GMT日期的xxx_date列。我使用Node JS从数据库查询日期字段。结果数据以我的本地时间格式显示。我想要相同的数据(格林尼治标准时间)。我试着用CONVERT_TZ方法更改我的查询。但结果数据不匹配。有人建议以正确的方式做到这一点。节点js在查询记录时自动将MySQL格式的GMT格式转换为本地格式

例如

xxx_date in DB: 2017-05-22 08:14:00 
the date I get after querying from DB: 2017-05-22T02:44:00.000Z 
but it should be either: 1:45 PM Monday, May 22, 2017, or 2017-05-22 08:14:00 

发生了什么这背后?

回答

0

在谷歌搜索了一天后,我发现这一点。通过在配置文件中将其更改为UTC,MySQL连接将默认使用本地时区(https://github.com/sidorares/node-mysql2/issues/262),我们可以在数据库中获取相同的数据。

在MySQL连接

var con = mysql.createConnection({ 
    host: "localhost", 
    user: "yourusername", 
    password: "yourpassword", 
    timezone:'UTC', 
    port: 3307 
}); 
相关问题