Skip to content
Advertisement

Add minutes and hours to string moment js

input – 15:30
output – 17:10
I try to do this:

JavaScript

but it doesn’t work, moment says “invalid date”

Advertisement

Answer

First of all you need to parse the string data, we know we’re using a valid hour.

JavaScript

You can use a second parameter in the moment function, something like this:

JavaScript

You simply need to know what format to convert your string to, read more about that in this documentation link.

Then, you can occupy the different builders to get the expected result.

JavaScript

And finally you will get your date time parsed.

Here is a working version of this:

JavaScript
JavaScript
Advertisement