fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.text.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void getWeekRange(int year, int week_no) {
  11.  
  12. Calendar cal = Calendar.getInstance();
  13. cal.set(Calendar.YEAR, year);
  14. cal.set(Calendar.WEEK_OF_YEAR, week_no);
  15.  
  16. cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  17. Date monday = cal.getTime();
  18. cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
  19. Date sunday = cal.getTime();
  20.  
  21. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
  22. System.out.println(sdf.format(monday)+" - " + sdf.format(sunday));
  23. }
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. for (int i = 0 ; i != 20 ; i++) {
  27. getWeekRange(2014, i+1);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.12s 380928KB
stdin
Standard input is empty
stdout
2013-12-30 - 2013-12-29
2014-01-06 - 2014-01-05
2014-01-13 - 2014-01-12
2014-01-20 - 2014-01-19
2014-01-27 - 2014-01-26
2014-02-03 - 2014-02-02
2014-02-10 - 2014-02-09
2014-02-17 - 2014-02-16
2014-02-24 - 2014-02-23
2014-03-03 - 2014-03-02
2014-03-10 - 2014-03-09
2014-03-17 - 2014-03-16
2014-03-24 - 2014-03-23
2014-03-31 - 2014-03-30
2014-04-07 - 2014-04-06
2014-04-14 - 2014-04-13
2014-04-21 - 2014-04-20
2014-04-28 - 2014-04-27
2014-05-05 - 2014-05-04
2014-05-12 - 2014-05-11