Skip to content

Commit

Permalink
chore: add 4 api
Browse files Browse the repository at this point in the history
  • Loading branch information
noahlam committed May 4, 2018
1 parent 64a2162 commit 20d81b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 25 additions & 3 deletions README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ miment().json()
}
```

#### `diff` 计算两个时间的毫秒差

```js
miment('2018-05-05 00:00:00').diff('2018-05-05 00:00:01')
// -1000
miment().diff('2018-05-05 00:00:00',2018-05-05 00:00:01')
// -1000
```
#### `stamp`
输出时间戳,不需参数。
Expand All @@ -150,6 +159,12 @@ miment().stamp()
// 1523408529932
```
#### `get`
输出给定单位的时间值 参数跟返回值都跟format一样,但是性能比format好很多
```js
miment().get('YYYY')
// 2018
```
#### `daysInMonth`
获取当前 `Miment` 对象所在月的天数。
Expand Down Expand Up @@ -185,8 +200,8 @@ miment().isBetween('2000-01-01','2020-01-01')
### 支持链式调用的方法
#### `add`
增加或减少时间。它接收 2 个参数:
#### `add` 和 `sub`
增加或减少时间。它们接收 2 个参数:
<table style='border-collapse:collapse;'>
<tr>
Expand Down Expand Up @@ -223,7 +238,7 @@ miment().add(-1, 'ww') // 减去一周,即获取上周的日期
miment().add(500,SSS) // 增加 500 毫秒
```
`add` 返回的值是增加完后的 `Miment` 对象,我们可以在它后面继续调用 mimont 支持的方法:
`add` 和 `sub` 返回的值是`增加/减少`完后的 `Miment` 对象,我们可以在它后面继续调用 mimont 支持的方法:
``` js
miment().add(1, 'DD').format()
Expand All @@ -236,6 +251,13 @@ miment().add(1, 'DD').format()
miment().add(1, 'DD').format().add(1, 'DD') // 报错
```
#### `set`
设置当前时间为一个固定值,用法跟参数都同`add/sub`
``` js
miment('2018-05-05 00:00:00').set(1999, 'YYYY').format()
// 1999-05-05 00:00:00
```
#### `distance`
计算 2 个时间的距离。它接收 2 个参数,返回一个 `Miment` 对象:
Expand Down
5 changes: 5 additions & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Update Log 更新日志
### v0.0.8 (2018-05-04)
1. added get api
1. added set api
1. added diff api
1. added sub api

### v0.0.7 (2018-04-26)
1. added isBefore api
Expand Down

0 comments on commit 20d81b0

Please sign in to comment.