- MomentJS 教程
- MomentJS - 主页
- MomentJS - 概述
- MomentJS - 环境设置
- MomentJS - 简介
- MomentJS - 解析日期和时间
- MomentJS - 日期验证
- MomentJS - Getter/Setter
- 操纵日期和时间
- 设置日期和时间格式
- MomentJS - 日期查询
- MomentJS - 国际化
- MomentJS - 定制
- MomentJS - 持续时间
- MomentJS - 实用程序
- MomentJS - 插件
- MomentJS - 示例
- MomentJS 有用资源
- MomentJS - 快速指南
- MomentJS - 有用的资源
- MomentJS - 讨论
MomentJS - 持续时间
MomentJS 提供了一个称为持续时间的重要功能,它可以处理给定单位的时间长度。在本章中,您将详细了解这一点。
可用的方法和持续时间
下表显示了与时刻持续时间一起使用的不同单位的持续时间可用的方法 -
| 方法 | 句法 |
|---|---|
| 创造 |
moment.duration(数字, 字符串); moment.duration(Number); moment.duration(Object); moment.duration(String); |
| 克隆 |
moment.duration().clone(); |
| 人性化 |
moment.duration(). humanize(); |
| 毫秒 |
moment.duration().milliseconds(); moment.duration().asMilliseconds(); |
| 秒数 |
moment.duration().seconds(); moment.duration().asSeconds(); |
| 分钟 |
moment.duration(). 分钟(); moment.duration().asMinutes(); |
| 小时 |
moment.duration().hours(); moment.duration().asHours(); |
| 天 |
moment.duration().days(); moment.duration().asDays(); |
| 周数 |
moment.duration().weeks(); moment.duration().asWeeks(); |
| 几个月 |
moment.duration().months(); moment.duration().asMonths(); |
| 年 | moment.duration().years(); moment.duration().asYears(); |
| 添加时间 |
moment.duration().add(Number, String); moment.duration().add(Number); moment.duration().add(Duration); moment.duration().add(Object); |
| 减去时间 |
moment.duration().subtract(Number, String); moment.duration().subtract(Number); moment.duration().subtract(Duration); moment.duration().subtract(Object); |
| 将持续时间与 Diff 一起使用 |
var 持续时间 = moment.duration(x.diff(y)) |
| 作为时间单位 |
moment.duration().as(String); |
| 获取时间单位 |
持续时间.get('小时'); 持续时间.get('分钟'); 持续时间.get('秒'); 持续时间.get('毫秒'); |
| 作为 JSON |
moment.duration().toJSON(); |
| 是一个持续时间 |
moment.isDuration(obj); |
| 作为 ISO 8601 字符串 |
moment.duration().toISOString(); |
| 语言环境 |
moment.duration().locale(); moment.duration().locale(String); |