给定calendar.week_of_year,如何获取本周开始和结束的日期?

给定calendar.week_of_year,如何获取本周开始和结束的日期?

问题描述:

给定为期一周,我怎样才能得到本周开始和结束的日期?给定calendar.week_of_year,如何获取本周开始和结束的日期?

例如: 假设日期为2017年1月1日。

Calendar calendar = Calendar.getInstance(); 
// Let's assume that we've set calendar to Jan/1/2017. 
Integer week_of_year = calendar.get(Calendar.WEEK_OF_YEAR) 

week_of_year will return 1.假定第1周是2017年1月1日至2017年1月7日之间的任何事情。

如何反转查找week_of_year = 1并获取2017年1月7日至2017年1月6日的最小/最大值?或任何其他有效的week_of_year值。

 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); 
     Calendar cal = Calendar.getInstance(); 
     cal.set(Calendar.WEEK_OF_YEAR, 1); 
     cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); 
     System.out.println("Start Date: " + sdf.format(cal.getTime())); 
     cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
     System.out.println("End Date: " + sdf.format(cal.getTime()));