有人可以解释一下为什么这不能正常工作。下面是一个使用moment.js计算CURRENT时间和变量时间之间差异的代码。
//breakfast
var breakfasttimeleft = moment(person.breakfast, 'HH:mm');
console.log("Person breakfast is at: " + person.breakfast + " -- Current time is at: " + currenttime);
console.log(breakfasttimeleft.diff(now, 'minutes'));
//lunch
var lunchtimeleft = moment(person.lunch, 'HH:mm');
console.log("Person lunch is at: " + person.lunch + " -- Current time is at: " + currenttime);
console.log(lunchtimeleft.diff(now, 'minutes'));
//dinner
var dinnertimeleft = moment(person.dinner, 'HH:mm');
console.log("Person dinner is at: " + person.dinner + " -- Current time is at: " + currenttime);
console.log(dinnertimeleft.diff(now, "minutes"));
})
这是输出:
CONSOLE LOG
Person breakfast is at: 18:35 -- Current time is at: 18:35
0
Person lunch is at: 23:35 -- Current time is at: 18:35
300
Person dinner is at: 04:35 -- Current time is at: 18:35
-840
晚餐在某些地方完全搞砸了,就像在上面和其他地方一样,它完美无缺。 基本上......如果另一个日期是在另一天,它不知道如何查看小时数,所以相反它会查找当天这两个小时之间的差异。
18:35至04:35。假设早上18:35到04:35,大约10个小时。相反,它所做的是计算从早上04:35到当天晚些时候18:35的时间。 我怎样才能解决这个问题才能正常工作?
看来我必须陈述一天以及..我怎样才能格式化它所以它是Day + Hours + Minutes