在我的节点应用程序中,我有一个MySQL DB,它有一个名为xxx_date的列,格式为GMT date格式。我正在使用Node JS从数据库中查询日期字段。产生的数据是我的本地时间格式。我想要相同的数据( GMT)。我也试着用CONVERT_TZ方法改变我的查询。但是结果数据是不匹配的。有人建议用一种正确的方法来做这件事。
例如
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这背后发生了什么?
发布于 2017-05-25 22:03:41
在谷歌上搜索了一天后,我找到了这个。MySQL连接将采用本地时区作为默认值,(https://github.com/sidorares/node-mysql2/issues/262)通过在配置文件中将其更改为协调时区,我们可以获得与数据库中相同的数据。
在mysql连接中
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
timezone:'UTC',
port: 3307
});https://stackoverflow.com/questions/44177482
复制相似问题