Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
7662c346
Commit
7662c346
authored
Jul 29, 2019
by
songxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加时间工具类
parent
ba0bf269
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
569 additions
and
433 deletions
+569
-433
LocalDateUtils.java
...src/main/java/com/pcloud/common/utils/LocalDateUtils.java
+569
-433
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/LocalDateUtils.java
View file @
7662c346
/**
/**
*
*
*/
*/
package
com
.
pcloud
.
common
.
utils
;
package
com
.
pcloud
.
common
.
utils
;
...
@@ -9,7 +9,13 @@ import java.time.LocalDate;
...
@@ -9,7 +9,13 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
java.time.temporal.TemporalAdjusters
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.string.StringUtil
;
...
@@ -19,436 +25,566 @@ import com.pcloud.common.utils.string.StringUtil;
...
@@ -19,436 +25,566 @@ import com.pcloud.common.utils.string.StringUtil;
* @创建时间:2017年7月20日,上午9:11:37 @版本:1.0
* @创建时间:2017年7月20日,上午9:11:37 @版本:1.0
*/
*/
public
class
LocalDateUtils
{
public
class
LocalDateUtils
{
private
static
final
DateTimeFormatter
TIME
=
DateTimeFormatter
.
ofPattern
(
"HHmmss"
);
private
static
final
DateTimeFormatter
TIME
=
DateTimeFormatter
.
ofPattern
(
"HHmmss"
);
private
static
final
DateTimeFormatter
SHORT_MILLISECOND
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmssSSS"
);
private
static
final
DateTimeFormatter
SHORT_MILLISECOND
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmssSSS"
);
private
static
final
DateTimeFormatter
SHORT_DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmss"
);
private
static
final
DateTimeFormatter
SHORT_DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmss"
);
private
static
final
DateTimeFormatter
DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
private
static
final
DateTimeFormatter
DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
private
static
final
DateTimeFormatter
SHORT_DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
private
static
final
DateTimeFormatter
SHORT_DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
private
static
final
DateTimeFormatter
DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
private
static
final
DateTimeFormatter
DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
/**
/**
* 获取当前的日期字符串(yyyy-MM-dd)
* 获取当前的日期字符串(yyyy-MM-dd)
*
*
* @return
* @return
*/
*/
public
static
String
getDateNow
()
{
public
static
String
getDateNow
()
{
return
LocalDate
.
now
().
format
(
DATE
);
return
LocalDate
.
now
().
format
(
DATE
);
}
}
/**
/**
* 获取当前的日期字符串(yyyyMMdd)
* 获取当前的日期字符串(yyyyMMdd)
*
*
* @return
* @return
*/
*/
public
static
String
getShortDateNow
()
{
public
static
String
getShortDateNow
()
{
return
LocalDate
.
now
().
format
(
SHORT_DATE
);
return
LocalDate
.
now
().
format
(
SHORT_DATE
);
}
}
/**
/**
* 获取当前的时间字符串(HHmmss)
* 获取当前的时间字符串(HHmmss)
*
*
* @return
* @return
*/
*/
public
static
String
getShortTimeNow
()
{
public
static
String
getShortTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
TIME
);
return
LocalDateTime
.
now
().
format
(
TIME
);
}
}
/**
/**
* 获取当前的日期字符串(yyyy-MM-dd HH:mm:ss)
* 获取当前的日期字符串(yyyy-MM-dd HH:mm:ss)
*
*
* @return
* @return
*/
*/
public
static
String
getDateTimeNow
()
{
public
static
String
getDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
DATETIME
);
return
LocalDateTime
.
now
().
format
(
DATETIME
);
}
}
/**
/**
* 获取当前的日期字符串(yyyyMMddHHmmss)
* 获取当前的日期字符串(yyyyMMddHHmmss)
*
*
* @return
* @return
*/
*/
public
static
String
getShortDateTimeNow
()
{
public
static
String
getShortDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_DATETIME
);
return
LocalDateTime
.
now
().
format
(
SHORT_DATETIME
);
}
}
/**
/**
* 获取当前的日期字符串(yyyyMMddHHmmssSSS)
* 获取当前的日期字符串(yyyyMMddHHmmssSSS)
*
*
* @return
* @return
*/
*/
public
static
String
getYmdhmss
()
{
public
static
String
getYmdhmss
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_MILLISECOND
);
return
LocalDateTime
.
now
().
format
(
SHORT_MILLISECOND
);
}
}
/**
/**
* 时间戳转换成字符串格式的时间
* 时间戳转换成字符串格式的时间
*
*
* @param time
* @param time
* @return
* @return
*/
*/
public
static
String
convertToString
(
long
time
)
{
public
static
String
convertToString
(
long
time
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()).
toString
().
replace
(
"T"
,
" "
);
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()).
toString
().
replace
(
"T"
,
" "
);
}
}
/**
/**
* 转换成Stirng类型的时间字符串(yyyy-MM-dd HH:mm:ss)
* 转换成Stirng类型的时间字符串(yyyy-MM-dd HH:mm:ss)
*
*
* @param localDateTime
* @param localDateTime
* @return
* @return
*/
*/
public
static
String
convertToString
(
LocalDateTime
localDateTime
)
{
public
static
String
convertToString
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
==
null
)
{
if
(
localDateTime
==
null
)
{
return
null
;
return
null
;
}
}
return
localDateTime
.
format
(
DATETIME
);
return
localDateTime
.
format
(
DATETIME
);
}
}
/**
/**
* 获取当前日前多少天以前的日期
* 获取当前日前多少天以前的日期
*
*
* @param days
* @param days
* @return
* @return
*/
*/
public
static
LocalDate
getMinusDays
(
long
days
)
{
public
static
LocalDate
getMinusDays
(
long
days
)
{
LocalDate
localDate
=
LocalDate
.
now
();
LocalDate
localDate
=
LocalDate
.
now
();
return
localDate
.
minusDays
(
days
);
return
localDate
.
minusDays
(
days
);
}
}
/**
/**
* 获取当前日前多少小时以前的日期
* 获取指定日前多少天以前的日期
*
*
* @param minutes
* @param date
* @return
* @param days
*/
* @return
public
static
LocalDateTime
getMinusHours
(
long
hours
)
{
*/
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
public
static
LocalDate
getMinusDays
(
LocalDate
date
,
long
days
)
{
return
localDateTime
.
minusHours
(
hours
);
if
(
date
==
null
)
{
}
throw
new
IllegalArgumentException
(
"date is null"
);
}
/**
return
date
.
minusDays
(
days
);
* 获取当前日前多少分钟以前的日期
}
*
* @param minutes
/**
* @return
* 获取当前日前多少小时以前的日期
*/
*
public
static
LocalDateTime
getMinusMinutes
(
long
minutes
)
{
* @param hours
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
* @return
return
localDateTime
.
minusMinutes
(
minutes
);
*/
}
public
static
LocalDateTime
getMinusHours
(
long
hours
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
/**
return
localDateTime
.
minusHours
(
hours
);
* 获取指定日前多少天以后的日期
}
*
* @param date
/**
* @param days
* 获取当前日前多少分钟以前的日期
* @return
*
*/
* @param minutes
public
static
LocalDateTime
getPlusDays
(
Date
date
,
long
days
)
{
* @return
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
*/
return
localDateTime
.
plusDays
(
days
);
public
static
LocalDateTime
getMinusMinutes
(
long
minutes
)
{
}
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
return
localDateTime
.
minusMinutes
(
minutes
);
/**
}
* Date转换为localDate
*
/**
* @param date
* 获取指定日前多少天以后的日期
* @return
*
*/
* @param date
public
static
LocalDate
convertDate
(
Date
date
)
{
* @param days
return
convertDateTime
(
date
).
toLocalDate
();
* @return
}
*/
public
static
LocalDateTime
getPlusDays
(
Date
date
,
long
days
)
{
/**
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
* Date转换为localDateTime
return
localDateTime
.
plusDays
(
days
);
*
}
* @param date
* @return
/**
*/
* String转换为localDate
public
static
LocalDateTime
convertDateTime
(
Date
date
)
{
*
if
(
date
==
null
)
{
* @param date
return
null
;
* @return
}
*/
Instant
instant
=
date
.
toInstant
();
public
static
LocalDate
convertDate
(
String
date
)
{
return
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
if
(
StringUtil
.
isEmpty
(
date
))
{
}
return
null
;
}
/**
return
LocalDate
.
parse
(
date
);
* string转换为localDateTime
}
*
* @param dateTime
/**
* @return
* Date转换为localDate
*/
*
public
static
LocalDateTime
convertDateTime
(
String
dateTime
)
{
* @param date
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
* @return
return
null
;
*/
}
public
static
LocalDate
convertDate
(
Date
date
)
{
if
(!
dateTime
.
contains
(
"T"
))
{
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
dateTime
=
dateTime
.
replace
(
" "
,
"T"
);
if
(
localDateTime
==
null
)
{
}
return
null
;
return
LocalDateTime
.
parse
(
dateTime
);
}
}
return
localDateTime
.
toLocalDate
();
}
/**
* 判断当前日期是否在指定日前之前,含当前日期
/**
*
* Date转换为localDateTime
* @param date
*
* @return
* @param date
*/
* @return
public
static
boolean
isBefore
(
Date
date
)
{
*/
if
(
date
==
null
)
{
public
static
LocalDateTime
convertDateTime
(
Date
date
)
{
return
false
;
if
(
date
==
null
)
{
}
return
null
;
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
}
return
LocalDateTime
.
now
().
isBefore
(
localDateTime
);
Instant
instant
=
date
.
toInstant
();
}
return
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
}
/**
* 判断当前日期是否在指定日前之后,含当前日期
/**
*
* string转换为localDateTime
* @param date
*
* @return
* @param dateTime
*/
* @return
public
static
boolean
isAfter
(
Date
date
)
{
*/
if
(
date
==
null
)
{
public
static
LocalDateTime
convertDateTime
(
String
dateTime
)
{
return
false
;
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
}
return
null
;
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
}
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
if
(!
dateTime
.
contains
(
"T"
))
{
}
dateTime
=
dateTime
.
replace
(
" "
,
"T"
);
}
/**
return
LocalDateTime
.
parse
(
dateTime
);
* 判断当前日期是否在指定日前之后,含当前日期
}
*
* @param localDateTime
/**
* @return
* 判断当前日期是否在指定日前之前,含当前日期
*/
*
public
static
boolean
isAfter
(
LocalDateTime
localDateTime
)
{
* @param date
if
(
localDateTime
==
null
)
{
* @return
return
false
;
*/
}
public
static
boolean
isBefore
(
Date
date
)
{
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
if
(
date
==
null
)
{
}
return
false
;
}
/**
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
* 判断第一个日期是否在第二个日前之后
return
LocalDateTime
.
now
().
isBefore
(
localDateTime
);
*
}
* @param firstDateTime
* @param secondDateTime
/**
* @return
* 判断当前日期是否在指定日前之后,含当前日期
*/
*
public
static
boolean
isAfter
(
LocalDateTime
firstDateTime
,
LocalDateTime
secondDateTime
)
{
* @param date
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
* @return
return
false
;
*/
}
public
static
boolean
isAfter
(
Date
date
)
{
return
firstDateTime
.
isAfter
(
secondDateTime
);
if
(
date
==
null
)
{
}
return
false
;
}
/**
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
* 判断第一个日期是否在第二个日前之后
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
*
}
* @param firstDateTime
* @param secondDateTime
/**
* @return
* 判断当前日期是否在指定日前之后,含当前日期
*/
*
public
static
boolean
isAfter
(
String
firstDateTime
,
String
secondDateTime
)
{
* @param localDateTime
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
* @return
return
false
;
*/
}
public
static
boolean
isAfter
(
LocalDateTime
localDateTime
)
{
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
if
(
localDateTime
==
null
)
{
}
return
false
;
}
/**
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
* 判断第一个日期是否在第二个日前之后
}
*
* @param firstDateTime
/**
* @param secondDateTime
* 判断第一个日期是否在第二个日前之后
* @return
*
*/
* @param firstDateTime
public
static
boolean
isAfter
(
Date
firstDateTime
,
Date
secondDateTime
)
{
* @param secondDateTime
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
* @return
return
false
;
*/
}
public
static
boolean
isAfter
(
LocalDateTime
firstDateTime
,
LocalDateTime
secondDateTime
)
{
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
}
return
false
;
}
/**
return
firstDateTime
.
isAfter
(
secondDateTime
);
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
}
*
* @param startDate
/**
* @param endDate
* 判断第一个日期是否在第二个日前之后
* @return
*
*/
* @param firstDateTime
public
static
boolean
isInIncludeDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
* @param secondDateTime
if
(
startDate
==
null
||
endDate
==
null
)
{
* @return
return
false
;
*/
}
public
static
boolean
isAfter
(
String
firstDateTime
,
String
secondDateTime
)
{
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
if
(
nowTime
.
isAfter
(
startDate
.
plusDays
(-
1
))
&&
nowTime
.
isBefore
(
endDate
.
plusDays
(
1
)))
{
return
false
;
return
true
;
}
}
else
{
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
return
false
;
}
}
}
/**
* 判断第一个日期是否在第二个日前之后
/**
*
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
* @param firstDateTime
*
* @param secondDateTime
* @param startDate
* @return
* @param endDate
*/
* @return
public
static
boolean
isAfter
(
Date
firstDateTime
,
Date
secondDateTime
)
{
*/
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
public
static
boolean
isInIncludeDateString
(
String
startDate
,
String
endDate
)
{
return
false
;
return
isInIncludeDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
}
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
/**
*
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
* @param startDate
*
* @param endDate
* @param startDate
* @return
* @param endDate
*/
* @return
public
static
boolean
isInBetweenDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
*/
if
(
startDate
==
null
||
endDate
==
null
)
{
public
static
boolean
isInIncludeDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
return
false
;
if
(
startDate
==
null
||
endDate
==
null
)
{
}
return
false
;
LocalDate
nowTime
=
LocalDate
.
now
();
}
if
(
nowTime
.
isAfter
(
startDate
)
&&
nowTime
.
isBefore
(
endDate
))
{
LocalDate
nowTime
=
LocalDate
.
now
();
return
true
;
if
(
nowTime
.
isAfter
(
startDate
.
plusDays
(-
1
))
&&
nowTime
.
isBefore
(
endDate
.
plusDays
(
1
)))
{
}
else
{
return
true
;
return
false
;
}
else
{
}
return
false
;
}
}
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
/**
*
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
* @param startDate
*
* @param endDate
* @param startDate
* @return
* @param endDate
*/
* @return
public
static
boolean
isInBetweenDateString
(
String
startDate
,
String
endDate
)
{
*/
return
isInBetweenDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
public
static
boolean
isInIncludeDateString
(
String
startDate
,
String
endDate
)
{
}
return
isInIncludeDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
/**
* 12:12:12)
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
*
*
* @param startDateTime
* @param startDate
* @param endDateTime
* @param endDate
* @return
* @return
*/
*/
public
static
boolean
isInBetweenDateTime
(
LocalDateTime
startDateTime
,
LocalDateTime
endDateTime
)
{
public
static
boolean
isInBetweenDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDateTime
==
null
||
endDateTime
==
null
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
return
false
;
return
false
;
}
}
LocalDateTime
nowTime
=
LocalDateTime
.
now
();
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
nowTime
.
isAfter
(
startDateTime
)
&&
nowTime
.
isBefore
(
endDateTime
))
{
if
(
nowTime
.
isAfter
(
startDate
)
&&
nowTime
.
isBefore
(
endDate
))
{
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
}
}
/**
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
* 12:12:12)
*
*
* @param startDate
* @param startDateTime
* @param endDate
* @param endDateTime
* @return
* @return
*/
*/
public
static
boolean
isInBetweenDateString
(
String
startDate
,
String
endDate
)
{
public
static
boolean
isInBetweenDateTime
(
Date
startDateTime
,
Date
endDateTime
)
{
return
isInBetweenDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
return
isInBetweenDateTime
(
convertDateTime
(
startDateTime
),
convertDateTime
(
endDateTime
));
}
}
/**
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
* 12:12:12)
*
*
* @param startDateTime
* @param startDateTime
* @param endDateTime
* @param endDateTime
* @return
* @return
*/
*/
public
static
boolean
isInBetweenDateTime
(
LocalDateTime
startDateTime
,
LocalDateTime
endDateTime
)
{
public
static
boolean
isInBetweenDateTimeString
(
String
startDateTime
,
String
endDateTime
)
{
if
(
startDateTime
==
null
||
endDateTime
==
null
)
{
return
isInBetweenDateTime
(
LocalDateTime
.
parse
(
startDateTime
),
LocalDateTime
.
parse
(
endDateTime
));
return
false
;
}
}
LocalDateTime
nowTime
=
LocalDateTime
.
now
();
/**
if
(
nowTime
.
isAfter
(
startDateTime
)
&&
nowTime
.
isBefore
(
endDateTime
))
{
* 获取两个时间差,天,时,分
return
true
;
*
}
else
{
* @param stratDateTime
return
false
;
* @param endDateTime
}
* @return
}
*/
public
static
long
[]
getDatePoor
(
LocalDateTime
stratDateTime
,
LocalDateTime
endDateTime
)
{
/**
if
(
stratDateTime
==
null
||
stratDateTime
==
null
)
{
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
return
null
;
* 12:12:12)
}
*
Duration
duration
=
Duration
.
between
(
stratDateTime
,
endDateTime
);
* @param startDateTime
// 计算差多少天
* @param endDateTime
long
day
=
duration
.
toDays
();
* @return
// 计算差多少小时
*/
long
hour
=
duration
.
toHours
()
-
day
*
24
;
public
static
boolean
isInBetweenDateTime
(
Date
startDateTime
,
Date
endDateTime
)
{
// 计算差多少分钟
return
isInBetweenDateTime
(
convertDateTime
(
startDateTime
),
convertDateTime
(
endDateTime
));
long
min
=
duration
.
toMinutes
()
-
duration
.
toHours
()
*
60
;
}
return
new
long
[]
{
day
,
hour
,
min
};
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
/**
* 12:12:12)
* 获取指定时间与当前日期相差多少小时
*
*
* @param startDateTime
* @param date
* @param endDateTime
* @return
* @return
*/
*/
public
static
long
getHourPoor
(
Date
date
)
{
public
static
boolean
isInBetweenDateTimeString
(
String
startDateTime
,
String
endDateTime
)
{
if
(
date
==
null
)
{
return
isInBetweenDateTime
(
LocalDateTime
.
parse
(
startDateTime
),
LocalDateTime
.
parse
(
endDateTime
));
return
-
1
;
}
}
return
getHourPoor
(
convertDateTime
(
date
));
/**
}
* 获取两个时间差,天,时,分
*
/**
* @param stratDateTime
* 获取指定时间与当前日期相差多少小时
* @param endDateTime
*
* @return
* @param dateTime
*/
* @return
public
static
long
[]
getDatePoor
(
LocalDateTime
stratDateTime
,
LocalDateTime
endDateTime
)
{
*/
if
(
stratDateTime
==
null
||
stratDateTime
==
null
)
{
public
static
long
getHourPoor
(
LocalDateTime
dateTime
)
{
return
null
;
if
(
dateTime
==
null
)
{
}
return
-
1
;
Duration
duration
=
Duration
.
between
(
stratDateTime
,
endDateTime
);
}
// 计算差多少天
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
long
day
=
duration
.
toDays
();
return
duration
.
toHours
();
// 计算差多少小时
}
long
hour
=
duration
.
toHours
()
-
day
*
24
;
// 计算差多少分钟
/**
long
min
=
duration
.
toMinutes
()
-
duration
.
toHours
()
*
60
;
* 获取指定时间与当前日期相差多少天
return
new
long
[]{
day
,
hour
,
min
};
*
}
* @param date
* @return
/**
*/
* 获取指定时间与当前日期相差多少小时
public
static
long
getDayPoor
(
Date
date
)
{
*
if
(
date
==
null
)
{
* @param date
return
-
1
;
* @return
}
*/
return
getDayPoor
(
convertDateTime
(
date
));
public
static
long
getHourPoor
(
Date
date
)
{
}
if
(
date
==
null
)
{
return
-
1
;
/**
}
* 获取指定时间与当前日期相差多少天
return
getHourPoor
(
convertDateTime
(
date
));
*
}
* @param dateTime
* @return
/**
*/
* 获取指定时间与当前日期相差多少小时
public
static
long
getDayPoor
(
LocalDateTime
dateTime
)
{
*
if
(
dateTime
==
null
)
{
* @param dateTime
return
-
1
;
* @return
}
*/
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
public
static
long
getHourPoor
(
LocalDateTime
dateTime
)
{
return
duration
.
toDays
();
if
(
dateTime
==
null
)
{
}
return
-
1
;
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toHours
();
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param date
* @return
*/
public
static
long
getDayPoor
(
Date
date
)
{
if
(
date
==
null
)
{
return
-
1
;
}
return
getDayPoor
(
convertDateTime
(
date
));
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param dateTime
* @return
*/
public
static
long
getDayPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
throw
new
IllegalArgumentException
(
"dateTime is null"
);
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toDays
();
}
/**
* 获取指定时间相差多少天
*
* @param startDate 格式:2017-01-01
* @param endDate 格式:2017-02-01
* @return
*/
public
static
long
getDayPoor
(
String
startDate
,
String
endDate
)
{
if
(
StringUtil
.
isEmpty
(
startDate
)
||
StringUtil
.
isEmpty
(
endDate
))
{
throw
new
IllegalArgumentException
(
"startDate or endDate is null"
);
}
return
getDayPoor
(
convertDate
(
startDate
),
convertDate
(
endDate
));
}
/**
* 获取指定时间相差多少天
*
* @param startDate
* @param endDate
* @return
*/
public
static
long
getDayPoor
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
throw
new
IllegalArgumentException
(
"startDate or endDate is null"
);
}
return
startDate
.
until
(
endDate
,
ChronoUnit
.
DAYS
);
}
/**
* 获取月份
*
* @param dateTime 时间格式:2019-01-01 00:00:00
* @return
*/
public
static
int
getMonth
(
String
dateTime
)
{
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
return
0
;
}
return
convertDateTime
(
dateTime
).
getMonthValue
();
}
/**
* 获取当月第一天
*
* @param date
* @return
*/
public
static
LocalDate
firstDay
(
LocalDate
date
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
with
(
TemporalAdjusters
.
firstDayOfMonth
());
}
/**
* 获取当月最后一天
*
* @param date
* @return
*/
public
static
LocalDate
lastDay
(
LocalDate
date
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
with
(
TemporalAdjusters
.
lastDayOfMonth
());
}
/**
* 获取指定日期和天数以前的日期时间集合(不含指定日期)
*
* @param date
* @return
*/
public
static
List
<
LocalDate
>
getBeforeDays
(
LocalDate
date
,
long
days
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
List
<
LocalDate
>
localDates
=
new
ArrayList
<>();
for
(
long
i
=
days
;
i
>
0
;
i
--)
{
localDates
.
add
(
getMinusDays
(
date
,
i
));
}
return
localDates
;
}
/**
* 获取指定日期之间的日期集合(含指定日期)
*
* @param startdate
* @param endDate
* @return
*/
public
static
List
<
LocalDate
>
getDates
(
LocalDate
startdate
,
LocalDate
endDate
)
{
if
(
startdate
==
null
||
endDate
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
Stream
.
iterate
(
startdate
,
date
->
date
.
plusDays
(
1
))
.
limit
(
ChronoUnit
.
DAYS
.
between
(
startdate
,
endDate
)
+
1
).
collect
(
Collectors
.
toList
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment