title: How to find date range for a given week on Android?
body: <p>This is driving me nuts!</p>
  
  <p>I have searched everywhere and found for example this question: <a href="https://stackoverflow.com/questions/3941700/how-to-get-dates-of-a-week-i-know-week-number">How to get dates of a week (I know week number)?</a></p>
  
  <p>However I can't get it to work in my implementation (On ANDROID API19 on NEXUS 7) :</p>
  
  <pre><code>public Pair&lt;String,String&gt; getWeekRange(int year, int week_no) {
  
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.WEEK_OF_YEAR, week_no);
  
      cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
      Date monday = cal.getTime();
      cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
      Date sunday = cal.getTime();
  
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
      return new Pair&lt;String,String&gt;(sdf.format(monday), sdf.format(sunday));
  }   
  </code></pre>
  
  <p>For ANY call to <code>getWeekRange(2014, WEEK)</code> it ALWAYS gives me the date range of week 2 (which happens to be the current week number today) ??</p>
  
  <p>Calendar seems to be a very confusing class, and there must be something I haven't understood. However according to the docs, <code>YEAR</code>, <code>WEEK_OF_YEAR</code> and <code>DAY_OF_WEEK</code> should be enough for me to set.</p>
  
  <pre><code>Some test data:
  01-10 18:28:54.730: V/JSON(24503): Week 1/2014 is date range:2014-01-06 to 2014-01-12
  01-10 18:28:54.730: V/JSON(24503): Week 2/2014 is date range:2014-01-06 to 2014-01-12
  01-10 18:28:54.730: V/JSON(24503): Week 3/2014 is date range:2014-01-06 to 2014-01-12
  01-10 18:28:54.730: V/JSON(24503): Week 4/2014 is date range:2014-01-06 to 2014-01-12
  01-10 18:28:54.740: V/JSON(24503): Week 5/2014 is date range:2014-01-06 to 2014-01-12
  01-10 18:28:54.740: V/JSON(24503): Week 1/2013 is date range:2013-01-07 to 2013-01-13
  01-10 18:28:54.740: V/JSON(24503): Week 2/2013 is date range:2013-01-07 to 2013-01-13
  01-10 18:28:54.740: V/JSON(24503): Week 3/2013 is date range:2013-01-07 to 2013-01-13
  01-10 18:28:54.740: V/JSON(24503): Week 4/2013 is date range:2013-01-07 to 2013-01-13
  01-10 18:28:54.740: V/JSON(24503): Week 5/2013 is date range:2013-01-07 to 2013-01-13
  </code></pre>
  
  <p>Can anyone see my mistake? Any help is appreciated.</p>
  
  <p>** EDIT **</p>
  
  <p>Seems that the code works fine on Windows, this is an isolated Android issue.</p>