Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 03639457
authored
Jul 11, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加日期方法
1 parent
535183d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
ne-shield-common/src/main/java/cn/com/glsx/admin/common/util/DateUtil.java
ne-shield-common/src/main/java/cn/com/glsx/admin/common/util/DateUtil.java
View file @
0363945
...
@@ -14,12 +14,7 @@ import java.time.LocalDateTime;
...
@@ -14,12 +14,7 @@ import java.time.LocalDateTime;
import
java.time.LocalTime
;
import
java.time.LocalTime
;
import
java.time.ZoneOffset
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -29,7 +24,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -29,7 +24,7 @@ import java.util.concurrent.TimeUnit;
* @version 1.0
* @version 1.0
* @history 2017年9月7日 create by liuyf@didihu.com.cn
* @history 2017年9月7日 create by liuyf@didihu.com.cn
*/
*/
public
class
DateUtil
extends
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
{
public
class
DateUtil
extends
com
.
glsx
.
plat
.
common
.
utils
.
DateUtils
{
public
static
String
YMDHMS
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
String
YMDHMS
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
String
YMD
=
"yyyy-MM-dd"
;
public
static
String
YMD
=
"yyyy-MM-dd"
;
...
@@ -464,7 +459,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -464,7 +459,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
dateStr
.
add
(
Lists
.
newArrayList
(
DateUtil
.
formatDateYmd
(
calendar
.
getTime
())));
dateStr
.
add
(
Lists
.
newArrayList
(
DateUtil
.
formatDateYmd
(
calendar
.
getTime
())));
}
}
//如果开始时间和结束时间是同一天。只取一天
//如果开始时间和结束时间是同一天。只取一天
if
(
Objects
.
equals
(
DateUtil
.
formatDateYmd
(
startDate
),
DateUtil
.
formatDateYmd
(
endDate
)))
{
if
(
Objects
.
equals
(
DateUtil
.
formatDateYmd
(
startDate
),
DateUtil
.
formatDateYmd
(
endDate
)))
{
return
dateStr
;
return
dateStr
;
}
}
dateStr
.
add
(
Lists
.
newArrayList
(
DateUtil
.
formatDateYmd
(
endDate
)));
dateStr
.
add
(
Lists
.
newArrayList
(
DateUtil
.
formatDateYmd
(
endDate
)));
...
@@ -497,7 +492,6 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -497,7 +492,6 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
}
}
public
static
String
getCurrentTime
(
String
format
)
{
public
static
String
getCurrentTime
(
String
format
)
{
if
(
format
==
""
||
format
==
null
)
{
if
(
format
==
""
||
format
==
null
)
{
format
=
YMDHMS
;
format
=
YMDHMS
;
...
@@ -1151,7 +1145,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1151,7 +1145,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
* 去掉0
* 去掉0
*/
*/
private
static
String
getIgnoreZero
(
long
number
,
String
unit
)
{
private
static
String
getIgnoreZero
(
long
number
,
String
unit
)
{
if
(
number
==
0
)
{
if
(
number
==
0
)
{
return
""
;
return
""
;
}
}
return
number
+
unit
;
return
number
+
unit
;
...
@@ -1443,6 +1437,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1443,6 +1437,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* HH 时 mm 分 ss 秒 时长
* HH 时 mm 分 ss 秒 时长
*
* @param timestamp 时长时间戳
* @param timestamp 时长时间戳
* @return HH 时 mm 分 ss 秒 时长
* @return HH 时 mm 分 ss 秒 时长
*/
*/
...
@@ -1461,6 +1456,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1461,6 +1456,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* 获取当前时间
* 获取当前时间
*
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
public
static
String
getNowDateTimeFormat
()
{
public
static
String
getNowDateTimeFormat
()
{
...
@@ -1475,23 +1471,24 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1475,23 +1471,24 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* 获取之后的时间
* 获取之后的时间
*
* @param dateTime1 yyyy-MM-dd HH:mm:ss
* @param dateTime1 yyyy-MM-dd HH:mm:ss
* @param dateTime2 yyyy-MM-dd HH:mm:ss
* @param dateTime2 yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
public
static
String
getAfterDateTimeStr
(
String
dateTime1
,
String
dateTime2
)
{
public
static
String
getAfterDateTimeStr
(
String
dateTime1
,
String
dateTime2
)
{
if
(
StringUtils
.
isEmpty
(
dateTime1
)
&&
StringUtils
.
isEmpty
(
dateTime1
))
{
if
(
StringUtils
.
isEmpty
(
dateTime1
)
&&
StringUtils
.
isEmpty
(
dateTime1
))
{
return
""
;
return
""
;
}
}
if
(
StringUtils
.
isEmpty
(
dateTime1
)
)
{
if
(
StringUtils
.
isEmpty
(
dateTime1
)
)
{
return
dateTime2
;
return
dateTime2
;
}
}
if
(
StringUtils
.
isEmpty
(
dateTime2
)
)
{
if
(
StringUtils
.
isEmpty
(
dateTime2
)
)
{
return
dateTime1
;
return
dateTime1
;
}
}
LocalDateTime
localDateTime1
=
LocalDateTime
.
parse
(
dateTime1
,
DateTimeFormatter
.
ofPattern
(
YMDHMS
));
LocalDateTime
localDateTime1
=
LocalDateTime
.
parse
(
dateTime1
,
DateTimeFormatter
.
ofPattern
(
YMDHMS
));
LocalDateTime
localDateTime2
=
LocalDateTime
.
parse
(
dateTime2
,
DateTimeFormatter
.
ofPattern
(
YMDHMS
));
LocalDateTime
localDateTime2
=
LocalDateTime
.
parse
(
dateTime2
,
DateTimeFormatter
.
ofPattern
(
YMDHMS
));
if
(
localDateTime1
.
isAfter
(
localDateTime2
))
{
if
(
localDateTime1
.
isAfter
(
localDateTime2
))
{
return
dateTime1
;
return
dateTime1
;
}
}
return
dateTime2
;
return
dateTime2
;
...
@@ -1499,6 +1496,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1499,6 +1496,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* 获取一天的最后时刻
* 获取一天的最后时刻
*
* @param dateStr yyyy-MM-dd
* @param dateStr yyyy-MM-dd
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
...
@@ -1510,6 +1508,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1510,6 +1508,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* 今日零点
* 今日零点
*
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
public
static
String
getTodayFirstDateTimeStr
()
{
public
static
String
getTodayFirstDateTimeStr
()
{
...
@@ -1521,6 +1520,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1521,6 +1520,7 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
/**
/**
* 今日 23:59:59
* 今日 23:59:59
*
* @return yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
*/
public
static
String
getTodayLastDateTimeStr
()
{
public
static
String
getTodayLastDateTimeStr
()
{
...
@@ -1537,4 +1537,5 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1537,4 +1537,5 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
System
.
out
.
println
(
getYearOfNow
());
System
.
out
.
println
(
getYearOfNow
());
System
.
out
.
println
(
getDaysByYearMonth
(
2021
,
5
));
System
.
out
.
println
(
getDaysByYearMonth
(
2021
,
5
));
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment