如何添加两个时刻?



有两个矩变量:

var m1 = moment("00:30:10", "hh:mm:ss") , m2 = moment("00:05:40", "hh:mm:ss");

如何添加这两个矩变量,以便我得到类似00:35:50

看起来您要做的是将持续时间相加。喜欢这个:

d1 = moment.duration("00:30:10")
d2 = moment.duration("00:05:40")
// this will change the value of d1 "in place"
d1.add(d2)
formatted = moment.utc(d1.asMilliseconds()).format("HH:mm:ss") 
console.log('The formatted time is:', formatted); // "00:35:50"
console.log('The "humanized" value is:', d1.humanize()) // 36 minutes
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>

最新更新