I Am writing my first big java project, and I have a fairly simple question.
How can I calculate (using java.util.Calendar) whether a condition is during a space of time, say whether or not its during school hours.
This is what i have so far...
private void autoSound() { Calendar schoolStart = Calendar.getInstance(); Calendar schoolEnd = Calendar.getInstance(); schoolStart.clear(); schoolEnd.clear(); schoolStart.set(year, month, day, 7, 30); schoolEnd.set(year, month, day, 18, 25); //14 if(soundy != 2) { return; } else { if(current.before(schoolStart) == true || current.after(schoolEnd) == true) { //TODO: Fix during school calculation sound = true; } else { sound = false; } System.out.println(sound); } }
Current is uptated like so just before this...
private void advanceTime() { Calendar Now = Calendar.getInstance(); year = Now.get(Calendar.YEAR); day = Now.get(Calendar.DATE); month = Now.get(Calendar.MONTH)+ 1; hour = Now.get(Calendar.HOUR); min = Now.get(Calendar.MINUTE); days1 = Now.get(Calendar.DAY_OF_WEEK); current.clear(); current.set(year, month, day, hour, min); if(hour == 0) { hour = 12; } }