I am using moment library and from front end I am getting time in HH:mm
I need to add hours and minutes to current time using moment.
Suppose I am getting <
You can create a duration for '05:30'
using moment.duration(String) and the use add(Duration).
As moment duration docs states, '05:30'
is a valid input for moment.duration(String):
As of 2.1.0, moment supports parsing ASP.NET style time spans. The following formats are supported.
The format is an hour, minute, second string separated by colons like
23:59:59
. The number of days can be prefixed with a dot separator like so7.23:59:59
. Partial seconds are supported as well23:59:59.999
.
Here a live sample:
const result = moment().add( moment.duration('05:30') );
console.log( moment().format() );
console.log( result.format() );