我正在尝试使用momentjs
,
但我无法获得hours
count
。
这是我尝试过的,
var date1 = moment('2016-10-08 10:29:23');
var date2 = moment('2016-10-08 11:06:55');
var diff = date2.diff(date1);
console.log(diff);
问题:我希望获得1 day 4 hrs
,4 hrs 2 min
等结果
答案 0 :(得分:1)
基于您想要做的事情的几个选项:
var date1 = moment('2016-10-08 10:29:23');
var date2 = moment('2016-10-09 11:06:55');
var diff = date2.diff(date1);
var duration = moment.duration(diff);
console.log(duration.humanize(true));
// "in a day"
console.log(`${duration.days()}d ${duration.hours()}h ${duration.minutes()}m`);
// "1d 0h 37m"
console.log(duration.asHours());
// 24.625555555555554