// 현재 시각이 영업시간인지 체크 .. 다음날 넘어갈때도 체크
checkTime(“08:00”,”03:00”);
public static boolean checkTime(String start_time , String end_time){
try {
int openHH = Integer.parseInt(start_time.split(":")[0]);
int openMM = Integer.parseInt(start_time.split(":")[1]);
int endHH = Integer.parseInt(end_time.split(":")[0]);
int endMM = Integer.parseInt(end_time.split(":")[1]);
LocalDateTime currentDateTime = LocalDateTime.now();
// Define the start time and end time for the specified period
LocalTime startTime = LocalTime.of(openHH, openMM);
LocalTime endTime = LocalTime.of(endHH, endMM);
// If the end time is before the start time, it means the period crosses midnight.
// Adjust the end time to be on the next day.
if (endTime.isBefore(startTime)) {
currentDateTime = currentDateTime.plusDays(1);
}
// Set the start time and end time on the current date
LocalDateTime startDateTime = currentDateTime.with(startTime);
LocalDateTime endDateTime = currentDateTime.with(endTime);
// Check if the current date and time fall within the specified period
if (currentDateTime.isAfter(startDateTime) || currentDateTime.isBefore(endDateTime)) {
return true;
} else {
return false;
}
}catch (Exception e){
return true;
}
}
'안드로이드' 카테고리의 다른 글
php7.0 fcm http v1 (0) | 2024.09.04 |
---|---|
안드로이드 tts 남자목소리 여자목소리 구분 (0) | 2024.07.05 |
카카오내비 길찾기 자바 (0) | 2024.03.28 |
android 타임아웃 주고 현재위치 찾기 (0) | 2024.02.28 |
android webview popup (0) | 2024.01.30 |