Calculating when the condition is during a time frame

• September 26th, 2011, 03:59 PM
YoungMaker
Calculating when the condition is during a time frame
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...

Code Java:

```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...

Code Java:

``` 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; } }```
• September 27th, 2011, 03:49 AM
Sean4u
Re: Calculating when the condition is during a time frame
So you need a method which tells you when a specified time is before some period's end time and after that period's start time? Hmmm, I think there are enough clues that a person reading the API doc for Calendar might be able to reasonably quickly find an answer...
• September 28th, 2011, 08:39 AM
YoungMaker
Re: Calculating when the condition is during a time frame
Perhaps I also need to look at how millitary time and Java time differ from 12 hour time to....

lol n00b mistake