/**
* 根据日期获得所在周的日期
* @param mdate
* @return
*/
@SuppressWarnings("deprecation")
public static List<Date> dateToWeek(Date mdate) {
int b = mdate.getDay();
Date fdate;
List<Date> list = newArrayList<Date>();
Long fTime = mdate.getTime() - b * 24*3600000;
for(inta = 1; a <= 7; a++) {
fdate = newDate();
fdate.setTime(fTime + (a * 24*3600000)); //一周从周一开始算,则使用此方式
//fdate.setTime(fTime + ((a-1) * 24*3600000)); //一周从周日开始算,则使用此方式
list.add(a-1, fdate);
}
return list;
}
/**
* 测试
* @param args
*/
public static void main(String[] args) {
// 定义输出日期格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd EEE");
Date currentDate = new Date();
// 比如今天是2015-02-03
List<Date> days = dateToWeek(currentDate);
System.out.println("今天的日期: " + sdf.format(currentDate));
for(Date date : days) {
System.out.println(sdf.format(date));
}
}原文:http://blog.csdn.net/huahuagongzi99999/article/details/43450549