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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
4 deletions
+140
-4
LocalDateUtils.java
...src/main/java/com/pcloud/common/utils/LocalDateUtils.java
+140
-4
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/LocalDateUtils.java
View file @
7662c346
...
...
@@ -9,7 +9,13 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
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.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
com.pcloud.common.utils.string.StringUtil
;
...
...
@@ -116,9 +122,23 @@ public class LocalDateUtils {
}
/**
* 获取指定日前多少天以前的日期
*
* @param date
* @param days
* @return
*/
public
static
LocalDate
getMinusDays
(
LocalDate
date
,
long
days
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
minusDays
(
days
);
}
/**
* 获取当前日前多少小时以前的日期
*
* @param minute
s
* @param hour
s
* @return
*/
public
static
LocalDateTime
getMinusHours
(
long
hours
)
{
...
...
@@ -150,13 +170,30 @@ public class LocalDateUtils {
}
/**
* String转换为localDate
*
* @param date
* @return
*/
public
static
LocalDate
convertDate
(
String
date
)
{
if
(
StringUtil
.
isEmpty
(
date
))
{
return
null
;
}
return
LocalDate
.
parse
(
date
);
}
/**
* Date转换为localDate
*
* @param date
* @return
*/
public
static
LocalDate
convertDate
(
Date
date
)
{
return
convertDateTime
(
date
).
toLocalDate
();
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
if
(
localDateTime
==
null
)
{
return
null
;
}
return
localDateTime
.
toLocalDate
();
}
/**
...
...
@@ -394,7 +431,7 @@ public class LocalDateUtils {
long
hour
=
duration
.
toHours
()
-
day
*
24
;
// 计算差多少分钟
long
min
=
duration
.
toMinutes
()
-
duration
.
toHours
()
*
60
;
return
new
long
[]
{
day
,
hour
,
min
};
return
new
long
[]{
day
,
hour
,
min
};
}
/**
...
...
@@ -445,10 +482,109 @@ public class LocalDateUtils {
*/
public
static
long
getDayPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
return
-
1
;
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