📅  最后修改于: 2020-10-22 06:24:16             🧑  作者: Mango
MomentJS提供了一个重要的功能,称为持续时间,可以处理给定单位的时间长度。在本章中,您将详细学习。
下表显示了与持续时间一起使用的不同单位的持续时间可用的方法-
Method | Syntax |
---|---|
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); |