【发布时间】:2021-01-24 04:46:23
【问题描述】:
我将 Postgres 用于我的数据库,并将 Sequelize 作为我的 ORM。我的代码有效,但我在这里看到的唯一问题是,我无法读取 Asia/Kolkata 时区中的数据。每次我尝试以该格式获取数据时,Sequelize 都会向我显示UTC。
我尝试了很多东西,但相同的 UTC 时区数据。在我的数据库中,数据以这种格式存储,仅 IST:
| starttime | endtime |
| 2020-10-07 10:30:00 | 2020-10-07 11:30:00 |
在 Sequelize 输出中,它给了我这个:
{
"startTime": "2020-10-07T05:00:00.000Z",
"endTime": "2020-10-07T06:00:00.000Z"
}
1. 我尝试过像这样配置我的 Sequelize 数据库文件:
const sequelize = new Sequelize('dbname', 'username', 'pwd', {
host: 'localhost',
dialect: 'postgres',
dialectOptions: {
useUTC: false,
dateStrings: true,
typeCast: (field, next) => { // for reading from database
if (field.type === 'DATETIME') {
return field.string()
}
return next()
}
},
timezone: '+05:30' // for writing the output
});
2.我也试过了,这个
const sequelize = new Sequelize('dbname', 'username', 'pwd', {
host: 'localhost',
dialect: 'postgres',
dialectOptions: {
useUTC: false,
timezone: '+05:30'
},
timezone: '+05:30'
});
3.也试过这样做
const sequelize = new Sequelize('dbname', 'username', 'pwd', {
host: 'localhost',
dialect: 'postgres',
dialectOptions: {
useUTC: false,
timezone: 'Asia/Calcutta' // also tried for Asia/Kolkata
},
timezone: 'Asia/Calcutta'
});
现在通过我的所有努力,我仍然可以在 UTC 时区获得时间。我尝试在Incognito mode 中获取输出,以检查浏览器上是否有任何缓存。没有变化。
【问题讨论】:
标签: node.js postgresql timezone sequelize.js