1:Date as = new Date(new Date().getTime()-24*60*60*1000); SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd"); String time = matter1.format(as); System.out.println(time);
取出数字型的时间 再减去24*60*60*1000,就得到昨天的时间了;
2:Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime()); System.out.println(yesterday);