2 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不知道像 getCurrentDate() 這樣的續(xù)集方法。
UTC 轉(zhuǎn)換問題似乎困擾著所有人(包括我自己)。 這里有一些細(xì)節(jié)。不確定是否 dialectOptions: {useUTC: false },有任何功能 - 只需添加 typeCast 方法即可為我解決問題。
dialectOptions: {
typeCast: function (field, next) { // for reading from database
if (field.type === 'DATETIME') {
return field.string()
}
return next()
},
結(jié)果可用于新的 js Date 對(duì)象:
const sql = 'select current_timestamp';
my_app.my_DB.query(sql, {raw: true, type: Sequelize.QueryTypes.SELECT})
.then(data => {
console.log(data[0].current_timestamp);
let d1 = new Date(data[0].current_timestamp);
});
這對(duì)我來說很好用 - 但一定要徹底測(cè)試!

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
像這樣添加useUTC屬性dialectOptions
dialectOptions: {
encrypt: false ,
options: {
useUTC: false, // for reading from database
},
},
添加回答
舉報(bào)