Node.js 如何比较时间和时间?
当我输入到9h时,代码工作,但当我输入10h、11h或12h时,代码不工作。Dialogflow可以识别22h、23h或00h。我做错了什么?对我的节目有什么建议吗? 我想用24小时制Node.js 如何比较时间和时间?,node.js,momentjs,dialogflow-es,chatbot,Node.js,Momentjs,Dialogflow Es,Chatbot,当我输入到9h时,代码工作,但当我输入10h、11h或12h时,代码不工作。Dialogflow可以识别22h、23h或00h。我做错了什么?对我的节目有什么建议吗? 我想用24小时制 function consulta(agent) { moment.locale("pt-BR"); const agora = moment(); let tempo = agent.parameters.time; let data = age
function consulta(agent) {
moment.locale("pt-BR");
const agora = moment();
let tempo = agent.parameters.time;
let data = agent.parameters.date;
let dataFormatada = moment(data).format('l');
let week = moment(data).weekday();
var a = moment(agent.parameters.time).tz("America/Recife");
let horaFormatada = moment(a).get('hour');
//let tempoFormatado = (moment(a).format('hh:mm'));
let tempoFormatado = (moment(a).format('LT'));
let horaAbrir = moment('08:00', 'LT');
let checkAbrir = moment(horaAbrir).get('hour');
let horaFechar = moment('17:00', 'LT');
let checkFechar = moment(horaFechar).get('hour');
if (horaFormatada < checkAbrir){
agent.add(`Marque após às 8h`);
} else if (horaFormatada > checkFechar){
agent.add(`Marque antes das 17h`);
} else if (week === 0 || week === 6){
agent.add(`Não abrimos nos finais de semana.`);
} else {
agent.add(`Ok, pode marcar`);
}
}
功能顾问(代理){
地点(“pt BR”);
const agora=力矩();
让tempo=agent.parameters.time;
让数据=agent.parameters.date;
设dataFormatada=矩(data).format('l');
let week=时刻(数据).weekday();
var a=时刻(代理参数时间).tz(“美国/累西腓”);
让horaFormatada=时刻(a)。得到('hour');
//设tempoformado=(矩(a).format('hh:mm');
设tempoformata=(矩(a).format('LT');
让Horarabrir=时刻('08:00','LT');
让checkAbrir=时刻(horaAbrir)。获取('hour');
让horaFechar=时刻('17:00','LT');
让checkFechar=时刻(horaFechar).get('hour');
如果(horaFormatadacheckFechar){
添加(`Marque antes das 17h`);
}否则如果(周===0 | |周===6){
agent.add(`Não abrimos nos finais de semana.`);
}否则{
agent.add(`Ok,pode marcar`);
}
}
我想我没有完全理解你所说的确切意思,问题在于它在10-12天内不起作用,但要让它将瞬间格式化为24小时格式,请使用HH
而不是HH
。这里有更多的文档,代码对我来说运行得很好,唯一的问题是当用户输入12h时,代码识别22h而不是12:00。11小时和10小时也有同样的问题。