Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
ops
Commits
746b2bf5
Commit
746b2bf5
authored
Sep 18, 2024
by
wujipeng
Browse files
日期计算优化
parent
84dcb2ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/service/impl/ContractServiceImpl.java
View file @
746b2bf5
...
...
@@ -32,7 +32,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractDao, ContractEntity
Date
beginTime
=
contractVO
.
getBeginTime
();
Date
endTime
=
contractVO
.
getEndTime
();
int
differ
=
(
int
)
DateUtils
.
daysBetween
(
beginTime
,
endTime
);
contractVO
.
setRemainingDays
(
differ
);
if
(
differ
>
NumberConstant
.
ZERO
)
{
contractVO
.
setRemainingDays
(
differ
);
}
else
{
contractVO
.
setRemainingDays
(
NumberConstant
.
ZERO
);
}
}
return
contractList
;
}
...
...
@@ -42,7 +46,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractDao, ContractEntity
List
<
ContractVO
>
list
=
baseMapper
.
listSecondLevel
(
homId
);
for
(
ContractVO
contractVO
:
list
)
{
int
l
=
(
int
)
DateUtils
.
daysBetween
(
new
Date
(),
contractVO
.
getEndTime
());
contractVO
.
setRemainingDays
(
l
);
if
(
l
>
NumberConstant
.
ZERO
)
{
contractVO
.
setRemainingDays
(
l
);
}
else
{
contractVO
.
setRemainingDays
(
NumberConstant
.
ZERO
);
}
}
return
list
;
}
...
...
src/main/java/com/ruzhoukj/sms/util/DateUtils.java
View file @
746b2bf5
...
...
@@ -65,7 +65,7 @@ public class DateUtils {
LocalDate
localDate2
=
date2
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
// 计算两个日期之间的天数差
return
Math
.
abs
(
ChronoUnit
.
DAYS
.
between
(
localDate1
,
localDate2
)
)
;
return
ChronoUnit
.
DAYS
.
between
(
localDate1
,
localDate2
);
}
/**
...
...
@@ -83,8 +83,12 @@ public class DateUtils {
public
static
void
main
(
String
[]
args
)
{
Date
[]
dates
=
getStartAndEndDateOfCurrentMonth
();
System
.
out
.
println
(
"Start date of this month: "
+
dates
[
0
]);
System
.
out
.
println
(
"End date of this month: "
+
dates
[
1
]);
// 获取当前月份的开始和结束日期
Date
[]
startAndEndDates
=
getStartAndEndDateOfCurrentMonth
();
Date
startAndEndDate
=
startAndEndDates
[
0
];
Date
endAndEndDate
=
startAndEndDates
[
1
];
long
l
=
daysBetween
(
startAndEndDate
,
endAndEndDate
);
System
.
out
.
println
(
l
);
}
}
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