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
6864d60d
Commit
6864d60d
authored
Jul 06, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
74abb526
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+57
-0
TestDateHelper.java
yzg-util-base/src/test/java/helper/TestDateHelper.java
+11
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
6864d60d
...
@@ -5,8 +5,10 @@ import com.yanzuoguang.util.exception.ExceptionHelper;
...
@@ -5,8 +5,10 @@ import com.yanzuoguang.util.exception.ExceptionHelper;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
/**
/**
...
@@ -1053,4 +1055,59 @@ public class DateHelper {
...
@@ -1053,4 +1055,59 @@ public class DateHelper {
return
(
Math
.
abs
(
month
+
result
)
+
surplus
);
return
(
Math
.
abs
(
month
+
result
)
+
surplus
);
}
}
/**
* 获取小时中的刻度时间
*
* @param day 拆分起止日期
* @return 拆分信息
*/
public
static
List
<
Day
>
splitDayTime
(
Day
day
)
{
Date
fromDate
=
getDateTime
(
day
.
getFrom
());
Date
toDate
=
getDateTime
(
day
.
getTo
());
Date
dayStart
=
fromDate
;
List
<
Day
>
ret
=
new
ArrayList
<>();
while
(
dayStart
.
getTime
()
<=
toDate
.
getTime
())
{
String
from
=
DateHelper
.
getDateTimeString
(
dayStart
);
Date
dayEnd
=
DateHelper
.
getDayEnd
(
dayStart
);
long
minEnd
=
Math
.
min
(
toDate
.
getTime
(),
dayEnd
.
getTime
());
String
to
=
DateHelper
.
getDateTimeString
(
new
Date
(
minEnd
));
ret
.
add
(
new
Day
(
from
,
to
));
dayStart
=
DateHelper
.
getDayStart
(
DateHelper
.
addDay
(
dayStart
,
1
));
}
return
ret
;
}
/**
* 每日日期拆分
*/
public
static
class
Day
{
private
String
from
;
private
String
to
;
public
Day
()
{
}
public
Day
(
String
from
,
String
to
)
{
this
.
from
=
from
;
this
.
to
=
to
;
}
public
String
getFrom
()
{
return
from
;
}
public
void
setFrom
(
String
from
)
{
this
.
from
=
from
;
}
public
String
getTo
()
{
return
to
;
}
public
void
setTo
(
String
to
)
{
this
.
to
=
to
;
}
}
}
}
yzg-util-base/src/test/java/helper/TestDateHelper.java
View file @
6864d60d
package
helper
;
package
helper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
public
class
TestDateHelper
{
public
class
TestDateHelper
{
...
@@ -47,4 +50,12 @@ public class TestDateHelper {
...
@@ -47,4 +50,12 @@ public class TestDateHelper {
Date
date
=
DateHelper
.
getDateTime
(
"00:00:00"
);
Date
date
=
DateHelper
.
getDateTime
(
"00:00:00"
);
System
.
out
.
println
(
"日期转换时间是否相等:"
+
(
date
!=
null
));
System
.
out
.
println
(
"日期转换时间是否相等:"
+
(
date
!=
null
));
}
}
@Test
public
void
testSplitDay
()
{
List
<
DateHelper
.
Day
>
days
=
DateHelper
.
splitDayTime
(
new
DateHelper
.
Day
(
"2023-7-1 10:00:00"
,
"2023-7-31 19:00:00"
));
String
json
=
JsonHelper
.
serialize
(
days
);
System
.
out
.
println
(
json
);
Assert
.
assertEquals
(
"[{\"from\":\"2023-07-01 10:00:00\",\"to\":\"2023-07-01 23:59:59\"},{\"from\":\"2023-07-02 00:00:00\",\"to\":\"2023-07-02 23:59:59\"},{\"from\":\"2023-07-03 00:00:00\",\"to\":\"2023-07-03 23:59:59\"},{\"from\":\"2023-07-04 00:00:00\",\"to\":\"2023-07-04 23:59:59\"},{\"from\":\"2023-07-05 00:00:00\",\"to\":\"2023-07-05 23:59:59\"},{\"from\":\"2023-07-06 00:00:00\",\"to\":\"2023-07-06 23:59:59\"},{\"from\":\"2023-07-07 00:00:00\",\"to\":\"2023-07-07 23:59:59\"},{\"from\":\"2023-07-08 00:00:00\",\"to\":\"2023-07-08 23:59:59\"},{\"from\":\"2023-07-09 00:00:00\",\"to\":\"2023-07-09 23:59:59\"},{\"from\":\"2023-07-10 00:00:00\",\"to\":\"2023-07-10 23:59:59\"},{\"from\":\"2023-07-11 00:00:00\",\"to\":\"2023-07-11 23:59:59\"},{\"from\":\"2023-07-12 00:00:00\",\"to\":\"2023-07-12 23:59:59\"},{\"from\":\"2023-07-13 00:00:00\",\"to\":\"2023-07-13 23:59:59\"},{\"from\":\"2023-07-14 00:00:00\",\"to\":\"2023-07-14 23:59:59\"},{\"from\":\"2023-07-15 00:00:00\",\"to\":\"2023-07-15 23:59:59\"},{\"from\":\"2023-07-16 00:00:00\",\"to\":\"2023-07-16 23:59:59\"},{\"from\":\"2023-07-17 00:00:00\",\"to\":\"2023-07-17 23:59:59\"},{\"from\":\"2023-07-18 00:00:00\",\"to\":\"2023-07-18 23:59:59\"},{\"from\":\"2023-07-19 00:00:00\",\"to\":\"2023-07-19 23:59:59\"},{\"from\":\"2023-07-20 00:00:00\",\"to\":\"2023-07-20 23:59:59\"},{\"from\":\"2023-07-21 00:00:00\",\"to\":\"2023-07-21 23:59:59\"},{\"from\":\"2023-07-22 00:00:00\",\"to\":\"2023-07-22 23:59:59\"},{\"from\":\"2023-07-23 00:00:00\",\"to\":\"2023-07-23 23:59:59\"},{\"from\":\"2023-07-24 00:00:00\",\"to\":\"2023-07-24 23:59:59\"},{\"from\":\"2023-07-25 00:00:00\",\"to\":\"2023-07-25 23:59:59\"},{\"from\":\"2023-07-26 00:00:00\",\"to\":\"2023-07-26 23:59:59\"},{\"from\":\"2023-07-27 00:00:00\",\"to\":\"2023-07-27 23:59:59\"},{\"from\":\"2023-07-28 00:00:00\",\"to\":\"2023-07-28 23:59:59\"},{\"from\":\"2023-07-29 00:00:00\",\"to\":\"2023-07-29 23:59:59\"},{\"from\":\"2023-07-30 00:00:00\",\"to\":\"2023-07-30 23:59:59\"},{\"from\":\"2023-07-31 00:00:00\",\"to\":\"2023-07-31 19:00:00\"}]"
,
json
);
}
}
}
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