title: See if the current time falls within a specific range of time in the current day in Java
body: <p>I am sure this was done 1000 times in 1000 different places. The question is I want to know if there is a better/standard/faster way to check if current "time" is between two time values given in <code>hh:mm:ss</code> format. For example, my big business logic should not run between <code>18:00:00 and 18:30:00</code>. So here is what I had in mind:</p>
  
  <pre><code> public static  boolean isCurrentTimeBetween(String starthhmmss, String endhhmmss) throws ParseException{
    DateFormat hhmmssFormat = new SimpleDateFormat("yyyyMMddhh:mm:ss");
    Date now = new Date();
    String yyyMMdd = hhmmssFormat.format(now).substring(0, 8);
  
    return(hhmmssFormat.parse(yyyMMdd+starthhmmss).before(now) &amp;&amp;
      hhmmssFormat.parse(yyyMMdd+endhhmmss).after(now));
   }
  </code></pre>
  
  <p>Example test case:</p>
  
  <pre><code>  String doNotRunBetween="18:00:00,18:30:00";//read from props file
    String[] hhmmss = downTime.split(",");
    if(isCurrentTimeBetween(hhmmss[0], hhmmss[1])){
     System.out.println("NOT OK TO RUN");
    }else{
     System.out.println("OK TO RUN");
    }
  </code></pre>
  
  <p>What I am looking for is code that is better</p>
  
  <ul>
  <li>in performance</li>
  <li>in looks</li>
  <li>in correctness</li>
  </ul>
  
  <p>What I am not looking for</p>
  
  <ul>
  <li>third-party libraries</li>
  <li>Exception handling debate </li>
  <li>variable naming conventions </li>
  <li>method modifier issues</li>
  </ul>