1 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 2 Calendar c = Calendar.getInstance(); 3 4 //过去七天 5 c.setTime(new Date()); 6 c.add(Calendar.DATE, - 7); 7 Date d = c.getTime(); 8 String day = format.format(d); 9 System.out.println("过去七天:"+day); 10 11 //过去一月 12 c.setTime(new Date()); 13 c.add(Calendar.MONTH, -1); 14 Date m = c.getTime(); 15 String mon = format.format(m); 16 System.out.println("过去一个月:"+mon); 17 18 //过去三个月 19 c.setTime(new Date()); 20 c.add(Calendar.MONTH, -3); 21 Date m3 = c.getTime(); 22 String mon3 = format.format(m3); 23 System.out.println("过去三个月:"+mon3); 24 25 //过去一年 26 c.setTime(new Date()); 27 c.add(Calendar.YEAR, -1); 28 Date y = c.getTime(); 29 String year = format.format(y); 30 System.out.println("过去一年:"+year); 31