首页 > 解决方案 > Dialogflow 实现中的日期时间函数

问题描述

谁能解释这些功能是什么意思?

setDate = agent.parameters.date.split('T')[0];
setTime = agent.parameters.time.split('T')[1].split(':')[0];

我正在进行预订预订,我希望 Google 助理以 12 小时格式打印出用户输入的时间。现在,当我在下午 4 点输入时,它会在 16 点打印出来。我的日期可以正常工作,但时间不行。我尝试过其他方法,但我不太明白“拆分”的意思。

例如。如果我说“book table today 4.30pm”,那么 google 将回复为“您已于 2018 年 11 月 23 日下午 4 点 30 分预订。” 但是现在使用代码,它会打印出“2018-11-23 at 16”

这是我的代码:

function makeBooking(agent){

bookingDate= agent.parameters.date.split('T')[0];
bookingTime = agent.parameters.time.split('T')[1].split(':')[0];

agent.add(`You have booked on ${availDate} at ${availTime}.`);

}

// A helper function that receives Dialogflow's 'date' and 'time' parameters and creates a Date instance.

function convertParametersDate(date, time){
  var resultDate = new Date(Date.parse(date.split('T')[0]));
  return resultDate;
}

标签: javascriptdialogflow-esactions-on-google

解决方案


但是,对于希望通过 fullfilment 更改日期格式的人来说,这可能为时已晚:

new Date('2020-05-01T12:00:00+05:30').toDateString()

Output: "Fri May 01 2020"

要查找小时和分钟,您可以使用getHours()getMinutes()方法。

有关更多信息,您可以查看:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date


推荐阅读