google 上的操作时间与我的当地时间不匹配

time in actions on google doesn't match my local time

我正在尝试使用 node.js firebase 云函数和 Dialogflow 开发 google 助手 因此,当我尝试 console.log 测试它的外观时,当我部署时一切正常,但是当我在模拟器上测试它时,句子中的时间与我的本地时间不匹配。它说现在是 11:00 上午,而在我的国家/地区是 18:00。谁能告诉我如何解决它?

如果您使用 Cloud Functions for Firebase,webhook 时间将设置为 GMT 时区 (+0)。这在某些情况下对于一致性很有用,缺点是它不能保证反映客户端。

在我们的recently published location sample we use a new timezone field in order to get the client timezone. With this, and the timezone in GMT, you can use a library like spacetime中获取用户本地时间。

const spacetime = require('spacetime');

app.handle('location_granted', (conv) => {
  const {id} = conv.request.device.timeZone;
  let localTime = spacetime(new Date());
  localTime = localTime.goto(id); // Set timezone

  conv.add(`The Local Time is ${localTime.format('{time}')}.`)
});