title: Get the current week in Java
body: <p>I want to get the current week with a given date, e.g if the date is <code>2016/01/19</code>, the result will be : <code>week number: 3</code></p>
  
  <p>I've seen some questions and answers about this but I'm not able to achieve what I want. Here is what I've done : </p>
  
  <pre><code>public static int getCurrentWeek() {
      String input = "20160115";
      String format = "yyyyMMdd";
      SimpleDateFormat df = new SimpleDateFormat(format);
      Date date = df.parse(input);
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      int week = cal.get(Calendar.WEEK_OF_YEAR);
  
      return week;
  }
  </code></pre>
  
  <p>I've took this code from <a href="https://stackoverflow.com/questions/16418661/java-get-week-number-from-any-date">this question</a> but I have an error on this line :</p>
  
  <pre><code>Date date = df.parse(input); 
  </code></pre>
  
  <p><em>unhandled exception type ParseException</em></p>