import java.text.SimpleDateFormat;
import java.util.Calendar;
public class test2 {
public static String getFirstDayOfWeek(int year, int week) {
Calendar firDay = Calendar.getInstance();
// 先滚动到该年
firDay.set(Calendar.YEAR, year);
// 滚动到周
firDay.set(Calendar.WEEK_OF_YEAR, week + 1);
// 得到该周第一天
firDay.set(Calendar.DAY_OF_WEEK, 2);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String firstDay = sdf.format(firDaya.getTime());
return firstDay;
}
public static String getLastDayOfWeek(int year,int week){
Calendar lasDay = Calendar.getInstance();
// 先滚动到该年
lasDay.set(Calendar.YEAR, year);
// 滚动到周
lasDay.set(Calendar.WEEK_OF_YEAR, week + 1);
// 得到该周第一天
lasDay.set(Calendar.DAY_OF_WEEK, 2);
// 得到该周最后一天
lasDay.add(Calendar.DAY_OF_WEEK, 4);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String lastDay = sdf.format(lasDay.getTime());
return lastDay;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.print("第38周的星期一到星期五的日期是:"+test2.getFirstDayOfWeek(, 1)+"——");
System.out.println(test2.getLastDayOfWeek(, 1));
}
}
运行结果: