我正在使用 momentjs 来操纵时间。我有一个小时、分钟、第二个字符串,如“00:30:00”。我想添加几分钟。使用 momentjs,我可以将此字符串转换为分钟,然后我可以轻松添加我想要的分钟。但我怎样才能回到刺痛的状态呢?
前 - moment.duration('00:30:00').asMinutes;会给我几分钟。 假设这给了 30 ,我可以再添加 30 分钟,使其成为 60 分钟。 如何使用 momentjs 将 60mins 再次转换为该字符串?
打印时
console.log(moment.duration('00:30:00').add(30, 'minutes'));
我正在获取
[object Object] { _bubble: function Zc(){var a,b,c,d,e,f=this._milliseconds,g=this._days,h=this._months,i=this._data;
// if we have a mix of positive and negative values, bubble down first
// check: https://github.com/moment/moment/issues/2166
// The following code bubbles up values, see the tests for
// examples of what that means.
// convert days to months
// 12 months -> 1 year
return f>=0&&g>=0&&h>=0||0>=f&&0>=g&&0>=h||(f+=864e5*Yc(_c(h)+g),g=0,h=0),i.milliseconds=f%1e3,a=s(f/1e3),i.seconds=a%60,b=s(a/60),i.minutes=b%60,c=s(b/60),i.hours=c%24,g+=s(c/24),e=s($c(g)),h+=e,g-=Yc(_c(e)),d=s(h/12),h%=12,i.days=g,i.months=h,i.years=d,this},
.... continued
最佳答案
您需要使用.add
.
moment.duration('00:30:00').add(30, 'minutes);
然后您可以运行 .asMinutes
来打印总持续时间。
moment.duration('00:30:00').add(30, 'minutes').asMinutes();
只有当您想要获取总分钟数时,您才希望始终最后使用 .asMinutes
。
关于javascript - 如何向时间字符串添加分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39174943/