2017-06-29 1 views
0

1週間の週が与えられた場合、週の開始日と終了日はどのように取得できますか?calendar.week_of_yearを指定すると、週の開始日と終了日を取得するにはどうすればよいですか?

例: 日付をJan/1/2017としましょう。

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は1を返します。おそらく、1週目は1月1日から2017年1月7日までの間です。

week_of_year = 1のルックアップを逆にして、Jan/7/2017の最小/最大値をJan/6/2017にするにはどうすればよいですか?または他の有効なweek_of_year値の場合

答えて

1
 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())); 
関連する問題