I know I can do anything and some more envolving Dates with momentjs.
(我知道我可以使用momentjs做任何事情,还可以做一些涉及日期的事情。)
But embarrassingly, I'm having a hard time trying to do something that seems simple: geting the difference between 2 times.(但是令人尴尬的是,我很难去做一件看起来很简单的事情:得到两次之间的差。)
Example:
(例:)
var now = "04/09/2013 15:00:00";
var then = "04/09/2013 14:20:30";
//expected result:
"00:39:30"
what I tried:
(我试过的)
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
I do not understand what is that "10" there.
(我不明白那里的“ 10”是什么。)
I live in Brazil, so we are utc-0300 if that is relevant.(我住在巴西,所以如果相关的话,我们是utc-0300。)
The result of moment.duration(now.diff(then))
is a duration with the correct internal values:
(moment.duration(now.diff(then))
是具有正确内部值的持续时间:)
days: 0
hours: 0
milliseconds: 0
minutes: 39
months: 0
seconds: 30
years: 0
So, I guess my question is: how to convert a momentjs Duration to a time interval?
(因此,我想我的问题是:如何将momentjs持续时间转换为时间间隔?)
I sure can use(我肯定可以用)
duration.get("hours") +":"+ duration.get("minutes") +:+ duration.get("seconds")
but i feel that there is something more elegant that I am completely missing.
(但是我觉得我完全没有什么更优雅的东西。)
update
(更新)
looking closer, in the above example now
is:(仔细观察,在上面的示例中now
是:)
Tue Apr 09 2013 15:00:00 GMT-0300 (E. South America Standard Time)…}
and moment(moment.duration(now.diff(then)))
is:
(而moment(moment.duration(now.diff(then)))
为:)
Wed Dec 31 1969 22:39:30 GMT-0200 (E. South America Daylight Time)…}
I am not sure why the second value is in Daylight Time (-0200)... but I am sure that i do not like dates :(
(我不确定为什么第二个值是夏令时(-0200)...但是我确定我不喜欢日期:()
update 2
(更新2)
well, the value is -0200 probably because 31/12/1969 was a date where the daylight time was being used... so thats that.
(好吧,该值为-0200,可能是因为1969年12月31日是使用夏令时的日期。)
ask by Leo translate from so