SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 20190705
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1);//-1.昨天時間 0.當前時間 1.明天時間 *以此類推
String time = sdf.format(c.getTime());
System.out.println("昨天的時間時間是:" + time);//20190704
----------------------------------------------------------------------------------------------------------
Date nowDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(nowDate);
calendar.add(Calendar.DAY_OF_YEAR, -15);
long last1FifteenTime = calendar.getTime().getTime();//獲取到15天之前得毫秒值
System.err.println(last1FifteenTime);
Date date = new Date();
Long time = date.getTime();//當前時間得毫秒
Date d = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//轉字符串
System.out.println(sdf.format(d));