以下的时间格式都是 yyyy-MM-dd 做判断的时候用 .compartTo() 方法
//eg
if(a.compartTo(b) > 0){
System.out.println("a>b");
}else if(a.compartTo(b) < 0){
System.out.println("a<b");
}else if(a.compartTo(b) == 0){
sout("a=b")
}
DateTimeFormatter df = DateTimeFormatter.
ofPattern
(
"yyyy-MM-dd"
);
//
TODO 获取当前时间
LocalDate inputDate = LocalDate.
now
();
//
TODO 当天开始
LocalDateTime today_start = LocalDateTime.
of
(LocalDate.
now
(), LocalTime.
MIN
);
//
TODO 当天结束
LocalDateTime today_end = LocalDateTime.
of
(LocalDate.
now
(), LocalTime.
MAX
);
String todayStartTime = today_start.format(DateTimeFormatter.
ofPattern
(
"yyyy-MM-dd"
));
String todayEndTime = today_end.format(DateTimeFormatter.
ofPattern
(
"yyyy-MM-dd"
));
//
TODO 本周开始时间
TemporalAdjuster FIRST_OF_WEEK =
TemporalAdjusters.
ofDateAdjuster
(localDate -> localDate.minusDays(localDate.getDayOfWeek().getValue()- DayOfWeek.
MONDAY
.getValue()));
String weekStart = df.format(inputDate.with(FIRST_OF_WEEK));
//
TODO 本周结束时间
TemporalAdjuster LAST_OF_WEEK =
TemporalAdjusters.
ofDateAdjuster
(localDate -> localDate.plusDays(DayOfWeek.
SUNDAY
.getValue() - localDate.getDayOfWeek().getValue()));
String weekEnd = df.format(inputDate.with(LAST_OF_WEEK));
//
TODO 本月的第一天
String monthStart = df.format(LocalDate.
of
(inputDate.getYear(),inputDate.getMonth(),1));
//
TODO 本月的最后一天
String monthEnd = df.format(inputDate.with(TemporalAdjusters.
lastDayOfMonth
()));