Add hours minutes with the format hh:mm using moment

Pro*_*fer 1 javascript timezone momentjs

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 05:30 from the frontend and I need to add to the current UTC time. How can I do that using momentjs?

I tried that but didn't work

moment().add('05:30', 'HH:mm')
Run Code Online (Sandbox Code Playgroud)

Vin*_*zoC 6

您可以创建一个持续时间'05:30'使用moment.duration(String)和使用add(Duration)

正如矩持续时间文档所述,'05:30'是的有效输入moment.duration(String)

2.1.0版本开始,时刻支持解析ASP.NET样式时间跨度。支持以下格式。

格式是小时,分钟,第二个字符串,用冒号()分隔23:59:59。天数可以像这样用点分隔符作为前缀7.23:59:59。也支持部分秒23:59:59.999

这是一个现场样本:

const result = moment().add( moment.duration('05:30') );
console.log( moment().format() );
console.log( result.format() );
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
Run Code Online (Sandbox Code Playgroud)