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
7371b706
Commit
7371b706
authored
Jul 16, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理分页重复提示BUG
parent
060438f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+22
-6
TestDateHelper.java
yzg-util-base/src/test/java/helper/TestDateHelper.java
+9
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
7371b706
...
@@ -61,23 +61,39 @@ public class DateHelper {
...
@@ -61,23 +61,39 @@ public class DateHelper {
/**
/**
* 获取时间
* 获取时间
*
*
* @param from 来源时间
* @param from 来源时间
* @param initMillSecond 是否初始化毫秒为0
* @return 结束时间
* @return 结束时间
*/
*/
public
static
Date
getDateTime
(
Object
from
)
{
public
static
Date
getDateTime
(
Object
from
,
boolean
initMillSecond
)
{
if
(
StringHelper
.
isEmpty
(
from
))
{
return
null
;
}
try
{
try
{
Date
to
=
null
;
if
(
from
instanceof
Date
)
{
if
(
from
instanceof
Date
)
{
return
(
Date
)
from
;
to
=
(
Date
)
from
;
}
else
if
(
from
==
null
)
{
}
else
{
return
null
;
to
=
DateAutoHelper
.
getAutoDate
(
String
.
valueOf
(
from
))
;
}
}
return
DateAutoHelper
.
getAutoDate
(
String
.
valueOf
(
from
));
to
=
initMillSecond
(
to
);
return
to
;
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
handleException
(
DateHelper
.
class
,
ex
,
from
);
ExceptionHelper
.
handleException
(
DateHelper
.
class
,
ex
,
from
);
}
}
return
null
;
return
null
;
}
}
/**
* 获取时间,会自动初始化毫秒为0
*
* @param from 来源时间
* @return 结束时间
*/
public
static
Date
getDateTime
(
Object
from
)
{
return
getDateTime
(
from
,
true
);
}
/**
/**
* Timestamp 转成 "yyyy-MM-dd HH:mm:ss"字符串
* Timestamp 转成 "yyyy-MM-dd HH:mm:ss"字符串
*
*
...
...
yzg-util-base/src/test/java/helper/TestDateHelper.java
View file @
7371b706
package
helper
;
package
helper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.text.ParseException
;
import
java.text.ParseException
;
...
@@ -23,4 +24,12 @@ public class TestDateHelper {
...
@@ -23,4 +24,12 @@ public class TestDateHelper {
System
.
out
.
println
(
"当前时间刻度:"
+
DateHelper
.
getHourUnitTime
(
new
Date
()));
System
.
out
.
println
(
"当前时间刻度:"
+
DateHelper
.
getHourUnitTime
(
new
Date
()));
}
}
@Test
public
void
testDateHelper1
()
{
Date
date
=
DateHelper
.
getDateTime
(
"2010-1-1"
);
ThreadHelper
.
sleep
(
50
);
Date
date1
=
DateHelper
.
getDateTime
(
"2010-1-1"
);
System
.
out
.
println
(
"日期转换时间是否相等:"
+
(
date
.
getTime
()
==
date1
.
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