SQL 返回的日期不正确

SQL is returning an incorrect date

我正在使用

我在 SQL 中的数据如下所示:

+--------------+----+--------------------+
|     date     | id | happinessIndicator |
+--------------+----+--------------------+
| '2019-10-20' |  1 | happy              |
| '2019-10-20' |  2 | happy              |
| '2019-10-20' |  3 | happy              |
| '2019-10-20' |  4 | happy              |
+--------------+----+--------------------+

这是我获取当天投票的代码

exports.day = function (req, res) {
    const today = moment().format('YYYY-MM-DD');
    knex('votes')
        .where('date', today)
        .then(function (resp) {
            res.json({
                status: true,
                message: 'ok',
                data: resp
            })
        })
        .catch(function (error) {
            res.json(
                {
                    status: false,
                    msg: error.code
                }
            )
        })
};

但我的结果是这样的:

为什么他return 2019-10-20不像有存储的?

这不是错误的日期,这是 UTC format

您可以在您的连接对象中设置您自己的时区格式,例如: knex({client,connection,useNullAsDefault: true,timezone: 'UTC',});