//获取当前年月日的前一天 并转换成字符串
//当前日期
Calendar calendar = Calendar.getInstance();
Date date = new Date();
calendar.setTime(date);
//calendar.add方法获取前一天日期
calendar.add(Calendar.DAY_OF_MONTH, -1);
date = calendar.getTime();
//格式转换
SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMdd”);
String s = sdf.format(date);
最后 输出字符串s 格式如下:
20211213
😎