var now = "04/09/2013 15:00:00";
var then = "04/09/2013 14:20:30";
//expected result:
"00:39:30"
我试过了。
var now = moment("04/09/2013 15:00:00");
var then = moment("04/09/2013 14:20:30");
console.log(moment(moment.duration(now.diff(then))).format("hh:mm:ss"))
//outputs 10:39:30
那里的"10"是什么意思?我现在是在UTC-0300时区。执行
moment.duration(now.diff(then))
的结果是一个内部值正确的持续时间。 days: 0
hours: 0
milliseconds: 0
minutes: 39
months: 0
seconds: 30
years: 0
如何将momentjs的持续时间转换为时间间隔?我可以使用:
duration.get("hours") +":"+ duration.get("minutes") +:+ duration.get("seconds")
但是有没有更优雅的东西呢?
现在
是:Tue Apr 09 2013 15:00:00 GMT-0300 (E. South America Standard Time)…}
而
moment(moment.duration(now.diff(then)))
是:Wed Dec 31 1969 22:39:30 GMT-0200 (E. South America Daylight Time)…}
数值为-0200,因为在1969年12月31日使用了夏令时。