title: Check if time is inbetween timerange in Android
body: <p>I am trying to check if the current time is in the range of a specified range. I made a method to check this, but it doesn't work. I'm not sure why not and how to get it to work. </p>
  
  <pre><code>private Calendar fromTime;
  private Calendar toTime;
  private Calendar currentTime;
  
  public boolean checkTime(String time) {
      try {
          String[] times = time.split("-");
          String[] from = times[0].split(":");
          String[] until = times[1].split(":");
  
          fromTime = Calendar.getInstance();
          fromTime.set(Calendar.HOUR, Integer.valueOf(from[0]));
          fromTime.set(Calendar.MINUTE, Integer.valueOf(from[1]));
  
          toTime= Calendar.getInstance();
          toTime.set(Calendar.HOUR, Integer.valueOf(until[0]));
          toTime.set(Calendar.MINUTE, Integer.valueOf(until[1]));
  
          currentTime = Calendar.getInstance();       
          currentTime.set(Calendar.HOUR, Calendar.HOUR_OF_DAY);
          currentTime.set(Calendar.MINUTE, Calendar.MINUTE);
          if(currentTime.after(fromTime) &amp;&amp; currentTime.before(toTime)){
              return true;
          }
       } catch (Exception e) {
           return false;
       }
      return false;
  }
  </code></pre>
  
  <p>I am trying to test it like this:</p>
  
  <pre><code>if(checkTime("06:00-19:00")){
      inRange = true;
  }
  </code></pre>
  
  <p>The NPE is gone, but it's still not calculating if the time is in the range of <code>fromTime</code> to <code>toTime</code>. Any help is very much appreciated!</p>