package test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Tesererew {
public static void main(String[] args) {
String [] arr=getBeforeSevenDay();
for (int i = 0; i < arr.length; i++) {
System.err.println(arr[i]);
}
}
public static String [] getBeforeSevenDay(){
String [] arr = new String[7];
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = null;
for (int i=0;i<7;i++){
c=Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, - i-1);
arr[6-i] =sdf.format(c.getTime());
}
return arr;
}
}
===================================================================
输出:
2016-03-09
2016-03-10
2016-03-11
2016-03-12
2016-03-13
2016-03-14
2016-03-15