Dan Lough Dan Lough - 1 month ago 6
Javascript Question

MomentJs. When time is converted why does it always output the hour with :10 as minutes?

I am trying to convert time from a date and was testing why it was always coming out as 11:10. I set up this simple test to see if it was still converting the same way and it is. This test gives start time formatted as 11:10. It should be 11:59.

var testDate = "11:59"
console.log("start time formatted", moment(testDate, ["h:mm"]).format("H:MM"));
console.log("start time", testDate);

Answer

I believe MM is numeric format for month which is current month October (10). Try to change it to mm like following code.

moment(testDate, ["h:mm"]).format("H:mm");