【问题标题】:How to set the correct time in cliniko API?如何在 cliniko API 中设置正确的时间?
【发布时间】:2020-10-11 23:35:20
【问题描述】:

我正在尝试创建一个预订平台。我面临一个问题,当我将请求发送到 cliniko 的 API 时,我的时间被保留在一个比我发送请求的时隙晚 4 小时的时隙上。这是我提出请求的代码

app.post('/makeBooking', (req, res) => {

  console.log('===========old=======start date: ',req.body.startDate)
  console.log('===========new=======end date: ',req.body.endDate)

  let newStartDate = moment.utc(req.body.startDate).format('YYYY-MM-DD HH:mm:ssZ')
  let newEndDate = moment.utc(req.body.endDate).format('YYYY-MM-DD HH:mm:ssZ')


   console.log('===========old=======start date: ',newStartDate)
  console.log('===========new=======end date: ', newEndDate)

  var data = JSON.stringify({
    "starts_at": newStartDate,
    "ends_at": newEndDate,
    "notes": req.body.note,
    "business_id": "436798402274003408",
    "practitioner_id": "436798398809508395",
    "patient_id": "6",
    "appointment_type_id": "436798401980402014"
  });

  axios(config)
    .then(function (response) {
      return res.status(200).json({ error: false, message: 'Success', data: response.data })
    })
    .catch(function (error) {
       console.log('==================================',error.response);
      console.log(error);
    });
})

我不确定将其转换为 utc 是否正确。我的时区是 EST。

【问题讨论】:

  • 似乎是时区问题。 API 服务器在哪个区域?期待 UTC 时间吗?
  • @DrewReese 是的,它预计 UTC 时间。但我已经将其转换为 UTC。
  • 您是否确认您的实际传出请求具有 UTC 日期时间?确认没有时间偏移仍然徘徊?您是否有权访问端点以确认它没有进行任何数据修改?

标签: javascript node.js reactjs debugging momentjs


【解决方案1】:

我可以通过像这样转换时区来解决这个问题

let newStartDate = moment(req.body.startDate, 'YYYY-MM-DD HH:mm:ss Z').utc().format()

let newEndDate = moment(req.body.endDate, 'YYYY-MM-DD HH:mm:ss Z').utc().format()

而不是这样做

let newStartDate = moment.utc(req.body.startDate).format('YYYY-MM-DDTHH:mm:ssZ')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2019-08-18
    • 1970-01-01
    • 2020-01-07
    相关资源
    最近更新 更多