Methods
(inner) date(date) → {String}
格式化日期为 yyyy-MM-dd 格式
Parameters:
Name | Type | Description |
---|---|---|
date | Date | |
- Source
Returns:
- Type:
- String
(inner) dateFormat(date, format) → {String}
格式化日期文本
Parameters:
Name | Type | Description |
---|---|---|
date | Date | | 传入日期 |
format | String | 传入格式如:yyyy-MM-dd |
- Source
Returns:
- Type:
- String
Example
dateFormat(new Date(), 'yyyy-MM-dd')
// 2023-01-02
(inner) datetime(date) → {String}
格式化日期为 yyyy-MM-dd hh:mm:ss 格式
Parameters:
Name | Type | Description |
---|---|---|
date | Date | |
- Source
Returns:
- Type:
- String
(inner) relativeTime(options) → {function}
将时间戳格式化相对时间
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | 相对时间模板,可使用{minute}模板方式替换当前文案,可使用的关键字有:minute、hour、year、month、day Properties
|
- Source
Returns:
返回一个方法,调用该方法并传入一个过去时间对象,可得到格式化的日期文案
- Type:
- function
Example
const getPastTimeLabel = relativeTime()
getPastTimeLabel(new Date())
// '刚刚'