title: How to get the date 7 days earlier date from current date in Java
body: <p>I am using </p>
  
  <pre><code>DateFormat dateFormat = 
  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  Date date = new Date();
  String fromdate = dateFormat.format(date);
  </code></pre>
  
  <p>to get the current date, how can I get the date 7 days back. For example, if today is 7th June 2013, how can I get 31th May 2013 in the same format as defined in date formatter?</p>
  
  <h2>Update</h2>
  
  <p>Got the solution:</p>
  
  <pre><code>DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  
          Date date = new Date();
          String todate = dateFormat.format(date);
  
          Calendar cal = Calendar.getInstance();
          cal.add(Calendar.DATE, -7);
          Date todate1 = cal.getTime();    
          String fromdate = dateFormat.format(todate1);
  </code></pre>