MomentJS教程

MomentJS 持续时间

MomentJS 提供了一个重要的特性,叫做持续时间,它处理给定单位的时间长度。在本章中,您将详细了解这一点。

具有持续时间的可用方法

下表显示了不同单位的持续时间可用的方法,以使用力矩持续时间-
方法 语法
创建
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
moment.duration().add(Number, String);
moment.duration().add(Number);
moment.duration(). add(Duration);
moment.duration().add(Object);
subtract
moment.duration().subtract(Number, String);
moment.duration().subtract(Number);
moment.duration()。减去(持续时间);
moment.duration().subtract(Object);
使用 Duration 和 Diff
var 持续时间 = moment.duration(x.diff(y))
作为时间单位
moment.duration().as(String);
获取时间单位
duration.get('hours');
duration.get('minutes');
duration.get('seconds');
duration.get('毫秒');
作为 JSON
moment.duration().toJSON();
是一个持续时间
moment.isDuration(obj);
作为 ISO 8601 字符串
moment.duration().toISOString();
语言环境
moment.duration().locale();
moment.duration().locale(String);
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4