javascript - 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;
}
解决方案
但是,对于希望通过 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
推荐阅读
- javascript - 如何使用内容安全策略安全地嵌入 Twitter 小部件
- ios - 需要在 swift 中构建类似 Instagram 的文本功能
- javascript - 改进 javascript 数字舍入
- vba - 如何使用 VBA 宏从 Web 服务器下载文件并将其保存到特定位置?
- git-bash - 将文件移动到 Git Bash 上的另一个文件夹
- android - 禁止访问二进制存储库
- node.js - Selenium docker 视频不能通过 network_mode 作为 docker-compose 中的主机工作
- ios - 如果用户更改付款方式,则不会调用 paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
- node.js - 编译失败怎么办?
- tkinter - 当我按下按钮时 GUI 没有关闭