[英]How to use format() on a moment.js duration?
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在持续时间对象上使用moment.js format
方法吗? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档中的任何地方都找不到它,而且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.此外,如果有任何其他库可以轻松适应此类功能,我会对推荐感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
I think this should be the best method to go about it. 我认为这应该是最好的方法。
var diff = moment(end).unix() - moment(start).unix();
moment.utc(moment.duration(diff).asMilliseconds()).format("HH:mm:ss.SSS");
or try this. 或试试这个。
var momentInSeconds = moment.duration(n,'seconds')
console.log(("0" + Math.floor(momentInSeconds.asHours())).slice(-2) + ':' + ("0" + momentInSeconds.minutes()).slice(-2) + ':' + ("0" + momentInSeconds.seconds()).slice(-2))
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Short version ( one-liner ):短版(单线):
moment.duration(durationInMs).asHours()|0||"00" + ":" + moment.utc(durationInMs).format("mm:ss")
Extended version:扩大的视野:
export const formatDuration = (durationInMs) => {
const hours = Math.floor(moment.duration(durationInMs).asHours()) || "00"
return hours + ":" + moment.utc(durationInMs).format("mm:ss")
}
Example cases:示例案例:
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
没有任何其他插件的 moment.js
moment().startOf('day').seconds(duration).format('HH:mm:ss')
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
Is there any way I can use the moment.js format
method on duration objects?有什么办法可以在duration对象上使用moment.js format
方法? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.我在文档的任何地方都找不到它,并且它也不是持续时间对象的属性。
I'd like to be able to do something like:我希望能够执行以下操作:
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')
Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.另外,如果还有其他任何可以轻松容纳这种功能的库,我会对建议感兴趣。
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.