moment.js中的完整人性化持续时间 [英] Full humanized durations in moment.js

查看:351
本文介绍了moment.js中的完整人性化持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在moment.js中尝试过

I tried this in moment.js

moment.duration(375,'days').humanize()

并得到一年" 作为答案,但我希望是一年零十天". 在moment.js中是否有办法获得完整的人性化价值?

and get "a year" as answer, but I would expect "a year and 10 days". Is there a way in moment.js to get the full humanized value?

推荐答案

Moment.js提供了fromNow函数来获取人类可读的持续时间,请参见

Moment.js is providing the fromNow function to get time durations in human readable fromat, see http://momentjs.com/docs/#/displaying/fromnow/

示例:

moment([2007, 0, 29]).fromNow(); // 4 years ago
moment().subtract(375, 'days').fromNow(); // a year ago

您需要使用@Fluffy建议的第三方lib

You need to use third party lib as suggested by @Fluffy

这篇关于moment.js中的完整人性化持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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