从 JS 时间戳转换为带时区的 Postgresql 时间戳

Convert from JS timestamp to Postgresql Timestamp with time zone

我有一个简单的 t = Date.now;,它通过 REST API 转到声明为 timestamp with time zone 的 Postresql t_time 列。 我收到错误:date/time field value out of range.

不能使用这个的答案因为我不写原始SQL 但使用 ORM(Knex.Js)。调用 db 只是为了进行转换对我来说似乎有点矫枉过正。 js 中的任何其他解决方案?

我怎么找不到转换器?我错过了什么吗?

注意:我只需要日期和时间hh:mm:ss,我不需要毫秒。

Date.now() 仅提供 since EPOCH 以毫秒为单位。

您需要一个 ISO 日期时间字符串。为此,请像这样设置 t

const t = new Date(Date.now()).toISOString();
console.log(t);