3天前:取负值
Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat sdf1 = new SimpleDateFormat(“yyyyMMdd”);
calendar1.add(Calendar.DATE, -3);
String three_days_ago = sdf1.format(calendar1.getTime());
System.out.println(three_days_ago);
同理,3天后,取正值即可:
Calendar calendar2 = Calendar.getInstance();
SimpleDateFormat sdf2 = new SimpleDateFormat(“yyyyMMdd”);
calendar2.add(Calendar.DATE, 3);
String three_days_after = sdf2.format(calendar2.getTime());
System.out.println(three_days_after);
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17469.html