MomentJS - Humanize

此方法以人类可读的格式显示日期。

语法

moment.duration().humanize();

示例

var a = moment.duration(24, "hours").humanize();

输出

Humanize

如果您需要在输出中添加 agoin 等后缀,请按如下方式添加 true 以进行人性化

示例

var a = moment.duration(24, "hours").humanize(true);

输出

Humanize Hours

示例

var a = moment.duration(-1, "days").humanize(true);

输出

Humanize Days

momentjs_durations.html