1 回答
TA贡献1802条经验 获得超5个赞
var a = moment([2017, 7, 1]);
var b = moment([2017, 7, 3, 12]);
var duration = moment.duration(b.diff(a));
var m = {
hours: `${parseInt(duration.asHours(), 10)}`,
minutes: `${parseInt(duration.asMinutes()) % 60}`,
seconds: `${parseInt(duration.asSeconds()) % 60}`,
toString: function() {
let m = `00${this.minutes}`.substr(this.minutes.length);
let s = `00${this.seconds}`.substr(this.seconds.length);
return `${this.hours}:${m}:${s}`;
}
};
console.log(m.toString());
补充:再来个简化点的版本
var a = moment([2017, 7, 1]);
var b = moment([2017, 7, 3, 12]);
var duration = moment.duration(b.diff(a));
var s = `${duration.asHours()}:${moment([2000, 1, 1]).add(duration).format("mm:ss")}`;
console.log(s);
添加回答
举报