title: Subtract one Day from date when inside a time interval
body: <p>I try to subtract one day when the time inside 0:00 am - 12:00 am.</p>
  
  <p>ex: <code>2012-12-14 06:35 am</code> => <code>2012-12-13</code></p>
  
  <p>I have done a function and It's work. But my question is any other better code in this case? Much simpler and easy to understand. </p>
  
  <pre><code>public String getBatchDate() {
  
      SimpleDateFormat timeFormatter = new SimpleDateFormat("H");
      int currentTime = Integer.parseInt(timeFormatter.format(new Date()));
      SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
      String Date = dateFormatter.format(new Date());
  
      if ( 0 &lt;= currentTime &amp;&amp; currentTime &lt;= 12){
          try {
              Calendar shiftDay = Calendar.getInstance();
              shiftDay.setTime(dateFormatter.parse(Date));
              shiftDay.add(Calendar.DATE, -1); 
              Date = dateFormatter.format(shiftDay.getTime());
          } catch (ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          Log.d("BatchDate:", Date);
      }
  
      return Date;
  
  }
  </code></pre>
  
  <p>THANKS,</p>