首页 文章

无法使用knes从postgres获取当前时间戳

提问于
浏览
0

我正在使用knex并使用原始查询来获取postgres数据库的当前时间戳 . 我在用

knex.raw('select now()').then(function(resp)
{
 console.log(resp)
})

但我无法得到理想的结果 . 请告诉我能做什么的解决方案 .

1 回答

  • 0

    这应该做:

    knex.select(knex.fn.now()).then(res => console.log(res[0].now));
    

    也许你还应该告诉你想要的结果是什么 .

    编辑:编辑查询以实际从响应中获取行和列,因为 select CURRENT_TIMESTAMP; 在postgres上返回以下内容:

    mikaelle=# select CURRENT_TIMESTAMP;
                  now              
    -------------------------------
     2018-12-10 14:48:01.472945+02
    (1 row)
    

相关问题