在javascript中从Web语音对象中提取日期

时间:2018-02-19 11:08:05

标签: javascript webspeech-api

有没有办法从web api语音中提取(省略)日期到新变量?演示听写保存在语音变量

var speech = "My dog's name is Tommy and i bought it on October 21st 2013";

我从用户那里获得然后将其转换为文本的听写包含不同的日期格式。 例如: 2017年12月2日,今年1月11日,2017年6月22日

1 个答案:

答案 0 :(得分:-1)

您可以将字符串拆分为子字符串数组 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

var speech = "My dog's name is Tommy and i bought it on October 21st 2013";

var getDate = speech.split("on")[1];
console.log(getDate);