Humanize1.6.0+
moment.duration().humanize();
Sometimes, you want all the goodness of moment#from
but you don't want to have to create two moments, you just want to display a length of time.
Enter moment.duration().humanize()
.
moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize(); // a day
By default, the return string is suffixless. If you want a suffix, pass in true as seen below.
moment.duration(1, "minutes").humanize(true); // in a minute
For suffixes before now, pass in a negative number.
moment.duration(-1, "minutes").humanize(true); // a minute ago
Invalid durations are humanized to the localized version of Invalid Date
.
moment.duration.invalid().humanize(); // Invalid Date
当前内容版权归 momentjs.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 momentjs.com .