我找到了一个解决方案:
Time startTime = getStartTime();
Time endTime = getEndTime();
Calendar startCalendarTime = Calendar.getInstance();
startCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, startTime.getHours(), startTime.getMinutes(), 0);
Calendar endCalendarTime = Calendar.getInstance();
endCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, endTime.getHours(), endTime.getMinutes(), 0);
Calendar midnightTime = Calendar.getInstance();
midnightTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 23, 59, 0);
Calendar nowCalendarTime = Calendar.getInstance();
nowCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH);
if (startCalendarTime.after(endCalendarTime)) {
if (nowCalendarTime.after(midnightTime)) {
startCalendarTime.add(Calendar.DAY_OF_YEAR, -1);
} else {
endCalendarTime.add(Calendar.DAY_OF_YEAR, 1);
}
}
int hours = nowCalendarTime.getTime().getHours();
int minutes = nowCalendarTime.getTime().getMinutes();
nowCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, hours, minutes, 0);
if (nowCalendarTime.after(startCalendarTime) && nowCalendarTime.before(endCalendarTime)) {
return true;
}
return false;