Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
9d34f592
Commit
9d34f592
authored
Aug 11, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ver1.1' of
http://192.168.0.204/yzg/yzg-util
parents
bb4f1f5b
9d6724cd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+21
-8
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
9d34f592
...
...
@@ -24,6 +24,9 @@ public class DateHelper {
public
static
final
String
INIT_TIME
=
"00:00:00"
;
public
static
final
String
FORMAT_DAY_HOUR_STRING
=
"yyyy-MM-dd HH:00:00"
;
public
static
final
String
FORMAT_SECOND_STRING
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
int
INIT_MILL_SECOND_NONE
=
0
;
public
static
final
int
INIT_MILL_SECOND_START
=
1
;
public
static
final
int
INIT_MILL_SECOND_END
=
2
;
private
static
final
int
MONTH_1
=
1
;
private
static
final
int
MONTH_2
=
2
;
...
...
@@ -80,19 +83,21 @@ public class DateHelper {
* @param initMillSecond 是否初始化毫秒为0
* @return 结束时间
*/
public
static
Date
getDateTime
(
Object
from
,
boolean
initMillSecond
)
{
public
static
Date
getDateTime
(
Object
from
,
int
initMillSecond
)
{
if
(
StringHelper
.
isEmpty
(
from
))
{
return
null
;
}
try
{
Date
to
=
null
;
Date
to
;
if
(
from
instanceof
Date
)
{
to
=
(
Date
)
from
;
}
else
{
to
=
DateAutoHelper
.
getAutoDate
(
String
.
valueOf
(
from
));
}
to
=
initMillSecond
(
to
);
if
(
initMillSecond
==
INIT_MILL_SECOND_NONE
)
{
return
to
;
}
return
initMillSecond
(
to
,
initMillSecond
);
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
handleException
(
DateHelper
.
class
,
ex
,
from
);
}
...
...
@@ -124,7 +129,7 @@ public class DateHelper {
* @return 结束时间
*/
public
static
Date
getDateTime
(
Object
from
)
{
return
getDateTime
(
from
,
true
);
return
getDateTime
(
from
,
INIT_MILL_SECOND_START
);
}
/**
...
...
@@ -303,12 +308,20 @@ public class DateHelper {
* 获取当天的日期
*
* @param date 需要的日期
* @param initMillSecond 初始化毫秒单位
* @return 返回的日期
*/
public
static
Date
initMillSecond
(
Date
date
)
{
public
static
Date
initMillSecond
(
Date
date
,
int
initMillSecond
)
{
if
(
initMillSecond
==
INIT_MILL_SECOND_NONE
)
{
return
date
;
}
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
if
(
initMillSecond
==
INIT_MILL_SECOND_START
)
{
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
}
else
{
c
.
set
(
Calendar
.
MILLISECOND
,
999
);
}
return
c
.
getTime
();
}
...
...
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