日期相关函数。
- Source:
Methods
(static) countMaxConsecutiveDate(dates) → {Number}
最大的连续天数数量。
- Source:
Parameters:
Name | Type | Description |
---|---|---|
dates |
Date
|
日期数组 |
Returns:
- Type:
-
Number
数量
Example
countMaxConsecutiveDate([
new Date(2015, 1, 1),
new Date(2015, 1, 4),
new Date(2015, 1, 5)
])
// 2
(static) dateFormatter(date, format) → {String}
时间格式化
- Source:
Parameters:
Name | Type | Description |
---|---|---|
date |
String
|
Date
|
需要格式化的时间。 |
format |
String
|
格式模板。 |
Returns:
- Type:
-
String
格式化后的时间字符。
Example
dateFormatter(new Date(2015, 1, 10, 14, 25, 33), 'yyyy-MM-dd hh:mm:ss')
dateFormatter(new Date(2015, 1, 10, 14, 25, 33), 'yyyy-M-d hh:mm:ss')
dateFormatter('2015-2-10 14:25:33', 'yyyy-M-d h:m:ss')
dateFormatter('2015-2-10 14:25:33', 'yyyy年第qq季度')
// 2015-02-10 14:25:33
// 2015-2-10 14:25:33
// 2015-2-10 14:25:33
// 2015年第01季度
(static) getMonthDays(date) → {Number}
获取月份天数
- Source:
Parameters:
Name | Type | Description |
---|---|---|
date |
Date
|
日期 |
Returns:
- Type:
-
Number
天数
(static) getPeriod(date, unit) → {Array}
根据日、周、月、年获取指定日期所在时间段。
- Source:
Parameters:
Name | Type | Description |
---|---|---|
date |
Date
|
String
|
日期 |
unit |
Date
|
String
|
单位:day, week, month, year |
Returns:
- Type:
-
Array
一个数组,包括开始日期和结束日期。
Example
getPeriod('2015-3-2','month')
// new Date('2015-3-1')
// new Date('2015-3-31')
(static) isEqualDate(stime, ttime) → {Boolean}
判断日期相等
- Source:
Parameters:
Name | Type | Description |
---|---|---|
stime |
Date
|
String
|
日期1 |
ttime |
Date
|
String
|
日期2 |
Returns:
- Type:
-
Boolean
true or false
(static) isEqualDateFuzzy(stime, ttime, tag) → {Boolean}
判断日期模糊相等
- Source:
Parameters:
Name | Type | Description |
---|---|---|
stime |
Date
|
String
|
日期1 |
ttime |
Date
|
String
|
日期2 |
tag |
String
|
相等界限,取值范围: |
Returns:
- Type:
-
Boolean
true or false
Example
isEqualDateFuzzy('2015-3-2','2015-3-2 12:56','date')
// true
(static) isLeapYear(year) → {Boolean}
判断是否是润年
- Source:
Parameters:
Name | Type | Description |
---|---|---|
year |
Number
|
年份 |
Returns:
- Type:
-
Boolean
true or false
(static) isValidDate(date) → {Boolean}
判断是否是合法日期对象
- Source:
Parameters:
Name | Type | Description |
---|---|---|
date |
Date
|
日期对象 |
Returns:
- Type:
-
Boolean
true or false
(static) toDate(time) → {Date}
转换成日期对象
- Source:
Parameters:
Name | Type | Description |
---|---|---|
time |
String
|
时间字符串 |
Returns:
- Type:
-
Date
日期对象