昨天:
SimpleDateFormat sdf=new SimpleDateFormat("yyyMMdd");
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(calendar.DATE,-1);
String date= sdf.format(calendar.getTime());
System.out.println("【定时】当前时间:"+date);
今天:
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyMMdd");
String date=sdf.format(d);
明天:
SimpleDateFormat sdf=new SimpleDateFormat("yyyMMdd");
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(calendar.DATE,1);
String date= sdf.format(calendar.getTime());
System.out.println("【定时】当前时间:"+date);
或者 昨天
Date date4 = new Date(new Date().getTime()-24*60*60*1000);
String time = sdf.format(date4);
System.out.println(time);