Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//今天
String today = df.format(c.getTime());
System.out.println(today);//比如今天是2017-02-08,则将输出2017-02-08
for (int i = 0; i < 10; i++) {
//今天-4天
// c.add(Calendar.DAY_OF_MONTH, -4);
c.add(Calendar.DAY_OF_MONTH, -i);
}
//将昨天格式化
String fouryesterday = df.format(c.getTime());
System.out.println(fouryesterday);//将输出2017-02-07
循环打印时间