MomentJS - 持续时间

MomentJS提供了一个称为持续时间的重要功能,可以处理给定单位的时间长度.在本章中,您将详细了解这一点.

持续时间可用的方法

下表显示了不同单位的持续时间可用方法使用时刻持续时间:

MethodSyntax
Creating

moment.duration(Number, String);

moment.duration(Number);

moment.duration(Object);

moment.duration(String);

Clone

moment.duration().clone();

Humanize

moment.duration().humanize();

Milliseconds

moment.duration().milliseconds();

moment.duration().asMilliseconds();

Seconds

moment.duration().seconds();

moment.duration().asSeconds();

Minutes

moment.duration().minutes();

moment.duration().asMinutes();

Hours

moment.duration().hours();

moment.duration().asHours();

Days

moment.duration().days();

moment.duration().asDays();

Weeks

moment.duration().weeks();

moment.duration().asWeeks();

Months

moment.duration().months();

moment.duration().asMonths();

Years

moment.duration().years();

moment.duration().asYears();

Add Time

moment.duration().add(Number, String);

moment.duration().add(Number);

moment.duration().add(Duration);

moment.duration().add(Object);

Subtract Time

moment.duration().subtract(Number, String);

moment.duration().subtract(Number);

moment.duration().subtract(Duration);

moment.duration().subtract(Object);

Using Duration with Diff

var duration = moment.duration(x.diff(y))

As Unit of Time

moment.duration().as(String);

Get Unit of Time

duration.get('hours');

duration.get('minutes');

duration.get('seconds');

duration.get('milliseconds');

As JSON

moment.duration().toJSON();

Is a Duration

moment.isDuration(obj);

As ISO 8601 String

moment.duration().toISOString();

Locale

moment.duration().locale();

moment.duration().locale(String);