我在获取两个时间戳(epoch格式)之间的时间差异方面存在问题.
我使用moment().format(“L LT”)将其转换为所需的日期时间格式(MM / DD / YYYY HH:MM(12小时)),
但现在的问题是,我希望hh:mm之间的时间差异
P.S.:它也可能超过24小时.
我尝试了什么:
let timeDiffms,duration,timedifference,
start moment(startTimeStampInMS).format("L LT"),
end = moment(endTimeStampInMS).format("L LT");
timeDiffms = moment(end, "MM/DD/YYYY HH:mm").diff(moment(start, "MM/DD/YYYY HH:mm"));
duration = moment.duration(timeDiffms);
timedifference = Math.floor(duration.asHours()) +":"+duration.minutes(); // result
//output I am getting
// start = "03/20/2017 3:11 PM" end="03/21/2017 9:45 AM" timedifference = "30:24", (incorrect)
// start = "03/20/2017 10:07 AM" end="03/23/2017 11:24 AM" timedifference = "73:17" (correct)
// start = "03/20/2017 3:11 PM" end="03/23/2017 11:31 AM" timedifference = "80:20" (incorrect) strange
我不知道这里发生了什么错.