public boolean judgeTimeScope() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
LocalDateTime localTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), dtf);
LocalDateTime startTime = LocalDate.now().atTime(6, 0, 0);
LocalDateTime endTime = LocalDate.now().atTime(8, 0, 0);
if (localTime.isAfter(endTime)) {
//时间08:00之后
return true;
} else if (localTime.isAfter(startTime) && localTime.isBefore(endTime)) {
//时间在 06:00-08:00 之间
return true;
} else {
//睡眠时间 0:00-06:00
startTime = LocalDate.now().atTime(0, 0, 0);
endTime = LocalDate.now().atTime(6, 0, 0);
if (localTime.isAfter(startTime) && localTime.isBefore(endTime)) {
return true;
return false;
}
public String getDayDate(int day) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, day);
return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
//前天getDayDate(-1)
//明天getDayDate(1)