如何利用时刻获得不同的时差? [英] How to get different time difference using moment?
问题描述
我需要使用片刻以 hh:mm:ss
格式获取两个日期之间的持续时间。但我无法得到确切的区别。这是我的例子。
let start = moment(2018-07-27T14:56:33.763Z);
let end = moment(2018-07-28T14:56:33.763Z);
让diff = end.diff(start);
让f = moment.utc(diff).format(HH:mm:ss);
alert(f);
对于上述日期,我需要输出 24:00: 00
,因为这是一天的差异。但是我得到 00:00:00
作为回复。
如果我要更改hrs,它应该显示为在那。我怎么能实现这个目标?有人可以帮我解决这个问题。
对 Moments GitHub Page 但这可能就是你所追求的:
让start = moment(2018-07-27T14:56:33.763Z);让结束=时刻(2018-07-28T14:56:33.763Z);让持续时间=时刻。 duration(end.diff(start));设f = Math.floor(duration.asHours())+ moment.utc(duration.asMilliseconds())。format(:mm:ss)alert(f);
< script src =https://cdnjs.cloudflare的.com / AJAX /库/ moment.js / 2.22.2 / moment.js>< /脚本>
I need to get the duration between two dates in hh:mm:ss
format using moment. but i am not able to get the exact difference. Here is my example.
let start = moment("2018-07-27T14:56:33.763Z");
let end = moment("2018-07-28T14:56:33.763Z");
let diff = end.diff(start);
let f = moment.utc(diff).format("HH:mm:ss");
alert(f);
For the above dates i need to get the output as 24:00:00
, because it's one day difference. But i am getting 00:00:00
as response.
If i am changing the hrs it should display based on that. how can i achieve this? can someone help me to fix this.
There's a rather lengthy discussion on Moments GitHub Page but this may be what you are after:
let start = moment("2018-07-27T14:56:33.763Z");
let end = moment("2018-07-28T14:56:33.763Z");
let duration = moment.duration(end.diff(start));
let f = Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss")
alert(f);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
By the way there is a plugin that someone created for this specific issue, which is posted on Moments Website as well.
这篇关于如何利用时刻获得不同的时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!