my demand: get the Monday and Sunday dates of the specified number of weeks according to the year and the number of weeks.
public static String getWeek(String year, String num) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(year));
int value = Integer.parseInt(num);
cal.set(Calendar.WEEK_OF_YEAR, value);
// 127
cal.set(Calendar.DAY_OF_WEEK, 2);
Date date = cal.getTime();
// 201610
value += 1;
cal.set(Calendar.WEEK_OF_YEAR, value);
// 127
cal.set(Calendar.DAY_OF_WEEK, 1);
Date date1 = cal.getTime();
return date2Month(date) + "/" + date2Date(date) + "~" + date2Month(date1) + "/" + date2Date(date1);
}
when I input two values of getWeek (2018 Android 24) for phones above getWeek 5.0, the result is 6.11-6.17, which is the result I want.
but when the phone is less than Android 5.0, pass in the same value, and the result is 6.11-6.10.
that is,
value += 1;
cal.set(Calendar.WEEK_OF_YEAR, value);
these two lines of code didn"t work. I wanted to increase the number of weeks by 1, but I didn"t succeed below Android 5.0.