Problem with time formatting when using Moment.js and Dialogflow

I'm having a problem typing some time in Dialogflow for my chatbot. I know that the system works with AM and PM, but I tried to format the date with the Moment.js (follow the code below), but it is not working. By placing an input of 9h, 10h, 11h or 12h it recognizes respectively as 21h, 22h, 23h and 00h. any suggestions?

function consulta(agent) {
    let data = moment(agent.parameters.date).format('L');
    let tempo = moment(agent.parameters.time).tz('America/Recife').format('HH:mm');
    agent.add(`${data} às ${tempo}`);
}
Author: Luiz Felipe, 2019-12-20

1 answers

According to the Documentation on Moment formatting.js , os tokens HH and mm format, respectively, for the hour in 24 hours (between 00 and 23) and the minute (between 00 and 59).

Thus, if you want to format, for example, the time 3 hours and 8 minutes PM, using the pattern above, you will have:

"HH:mm" → 15:08

If you don't want formatting in the 24-hour template, you need to use the tokens hh and mm, in addition to A - to indicate AM or PM.

So, if you want to format the same time as before – 3 hours and 8 minutes PM-using this new pattern, you will have:

"hh:mm A" → 03:08 PM

So basically:

┌─────────┬─────────┬────────────────────────────┐
│  Tipo   │ Formato │          Exemplo           │
├─────────┼─────────┼────────────────────────────┤
│ Período │ A       │ AM (ou) PM                 │
│ Período │ a       │ am (ou) pm                 │
│ Horas   │ HH      │ 01, 02, ... 12, 13, ... 23 │
│ Horas   │ hh      │ 01, 02, ... 12, 01, ... 11 │
└─────────┴─────────┴────────────────────────────┘

Again, to learn more about these formats, see the formatting documentation.

 1
Author: Luiz Felipe, 2019-12-26 17:10:07