
- MomentJS 教程
- MomentJS - 首頁
- MomentJS - 概述
- MomentJS - 環境設定
- MomentJS - 簡介
- MomentJS - 解析日期和時間
- MomentJS - 日期驗證
- MomentJS - Getter/Setter
- 操作日期和時間
- 格式化日期和時間
- MomentJS - 日期查詢
- MomentJS - 國際化
- MomentJS - 自定義
- MomentJS - 時長
- MomentJS - 實用工具
- MomentJS - 外掛
- MomentJS - 示例
- MomentJS 有用資源
- MomentJS - 快速指南
- MomentJS - 有用資源
- MomentJS - 討論
MomentJS - 時長
MomentJS 提供了一個重要的功能,稱為時長 (durations),用於處理給定單位的時間長度。在本節中,您將詳細瞭解這一點。
時長可用方法
下表顯示了時長中可用於不同單位的各種方法:
方法 | 語法 |
---|---|
建立 |
moment.duration(數字, 字串); moment.duration(數字); moment.duration(物件); moment.duration(字串); |
克隆 |
moment.duration().clone(); |
人性化 |
moment.duration().humanize(); |
毫秒 |
moment.duration().milliseconds(); moment.duration().asMilliseconds(); |
秒 |
moment.duration().seconds(); moment.duration().asSeconds(); |
分鐘 |
moment.duration().minutes(); 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(數字, 字串); moment.duration().add(數字); moment.duration().add(時長); moment.duration().add(物件); |
減去時間 |
moment.duration().subtract(數字, 字串); moment.duration().subtract(數字); moment.duration().subtract(時長); moment.duration().subtract(物件); |
將時長與 diff 一起使用 |
var duration = moment.duration(x.diff(y)) |
作為時間單位 |
moment.duration().as(字串); |
獲取時間單位 |
duration.get('hours'); duration.get('minutes'); duration.get('seconds'); duration.get('milliseconds'); |
作為 JSON |
moment.duration().toJSON(); |
是否是時長 |
moment.isDuration(物件); |
作為 ISO 8601 字串 |
moment.duration().toISOString(); |
語言環境 |
moment.duration().locale(); moment.duration().locale(字串); |