title: Checking time interval in java
body: <p>I want some Java code that will tell me when school is open based on the current time.</p>
  
  <p>When I call this method between 9AM and 6PM it should return "school is open", otherwise it should return "school is closed" after 6 pm and before 9 am.</p>
  
  <pre><code>public Calendar shopStartTime(String msg)
  {
      Calendar currentTime = Calendar.getInstance();
      Calendar schoolTime = Calendar.getInstance();
      Calendar schoolClosedTime = Calendar.getInstance();
      schoolTime.set(Calendar.HOUR_OF_DAY, 9);
      schoolTime.set(Calendar.MINUTE, 0);
      schoolTime.set(Calendar.SECOND, 0);
      schoolTime.set(Calendar.MILLISECOND, 0);
      schoolClosedTime.set(Calendar.HOUR_OF_DAY, 18);
      schoolClosedTime.set(Calendar.MINUTE, 0);
      schoolClosedTime.set(Calendar.SECOND, 0);
      schoolClosedTime.set(Calendar.MILLISECOND, 0);
      if (schoolTime.compareTo(currentTime) &lt;= 0 &amp;&amp; 
         (currentTime.compareTo(schoolClosedTime)&gt;=0))
      {
          // check for time
          Toast.makeText(getSherlockActivity(), "school is closed ", 
              Toast.LENGTH_SHORT).show();
      }
      else 
      {
          Toast.makeText(getSherlockActivity(), " school is open", 
              Toast.LENGTH_SHORT).show();
      }
      return currentTime;
  }
  </code></pre>
  
  <p>But the code is not working because it always returns the same result.  How do I test if one time is between two other time of days?</p>