如何在moment.js持续时间内使用format()? [英] How do I use format() on a moment.js duration?

查看:115
本文介绍了如何在moment.js持续时间内使用format()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么办法可以在持续时间内使用 moment.js 格式方法对象?我在文档中的任何地方都找不到它,并且它不会被视为持续时间对象的属性。

Is there any way I can use the moment.js format method on duration objects? 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')

此外,如果有任何其他库可以轻松容纳这种功能,我会对reccomendations感兴趣。

Also, if there are any other libraries which can easily accomodate this sort of functionality, I'd be interested in reccomendations.

谢谢!

推荐答案

我们正在研究在moment.js中为持续时间添加某种格式。请参阅 https://github.com/timrwood/moment/issues/463

We are looking into adding some kind of formatting to durations in moment.js. See https://github.com/timrwood/moment/issues/463

其他一些可能有用的图书馆是 http://countdownjs.org/ https://github.com/icambron/twix.js

A couple other libraries that might help out are http://countdownjs.org/ and https://github.com/icambron/twix.js

这篇关于如何在moment.js持续时间内使用format()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆