如何在 nodejs 中创建时区值为 (currentdate-7) 天的时间戳?

How to create a timestamp with timezone value which is (currentdate-7) days in nodejs?

我的时区格式的 postgresql 时间戳是 2020-07-03T07:01:42.231433+00:00

如何在 nodejs 中创建这样一个时间戳值(当前日期 - 7 天)?

我的目标是创建一个 grapghl 查询来更新 postgresql 中超过 7 天的所有行。

mutation MyMutation($timestampInterval: timestamptz) {
  update_Offers(where: {createdAt: {_lt: $timestampInterval}}, _set: {active: false}) {
    affected_rows
  }
}

在此查询中,我正在比较 createdAt 时间(即带时区的时间戳)是否小于我提供的带时区值的时间戳。

使用 moment.js 库。 使用起来相当简单。

const moment = require('moment');
const oldDate = moment().substract(7,'d').format('YYYY-MM-DDTHH:mm:ss+00:00');