以下は、startTime と endTime で 2 つの文字列を取り、好きなように範囲を定義する必要がある範囲オブジェクトと比較するコードです。コードを説明するためにコメントを付けました。
/*
* this method will split hhmm time into two parts.
*/
public String[] getTimeHHMM(String time){
String hhmm[] = new String[2];
if(time !=null && time.length() > 1){
hhmm[0] = time.substring(0, time.length() - 2);
hhmm[1] = time.substring(time.length() - 2, time.length());
}
else{
// time not formatted correctly so deal with here
hhmm[0] = "";
hhmm[1] = time;
}
return hhmm;
}
//assuming hrs is a string containing only one time in the format hhmm
String startTime[] = getTimeHHMM(startTimeStr);
String endTime[] = getTimeHHMM(endTimeStr);
int startTimeHrs = Integer.parseInt(startTime[0]);
int startTimeMins = Integer.parseInt(startTime[1]);
int endTimeHrs = Integer.parseInt(endTime[0]);
int endTimeMins = Integer.parseInt(endTime[1]);
Date start = new Date();
Date end = new Date();
Calendar start = Calendar.getInstance();
start.set(Calendar.HOUR_OF_DAY, startHrs);
start.set(Calendar.MINUTE, startMins );
Calendar end = Calendar.getInstance();
end.set(Calendar.HOUR_OF_DAY, endHrs);
end.set(Calendar.MINUTE, endMins );
///lets say the range is startRange and endRange it should be Calendar instances, you will need to construct these as I did above with setting your range whatever you like
Calendar endRange;
Calendar startRange;
if(start.compareTo(startRange) >= 0 && end.compareTo(endRange) <=0 ){
// Here it means it is within working hours
}