1、当前日期的下一月的当前日期
private static String getLastMonthDate(String dataTime) throws ParseException {
//时间字符串转 LocalDate 类型
LocalDate today = LocalDate.parse(dataTime);
//当前月份+(-1)
today = today.minusMonths(-1);
//LocalDate日期格式是”YYYY-MM-DD”,只需要用toString()就可以转化成字符串类型
return today.toString();
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
2、另外一种方式
登录后复制
public static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat(“yyyy-MM-dd”);
private static String getLastMonthDate(String repeatDate) {
Calendar calendar = Calendar.getInstance();
try {
if(repeatDate!=null && !””.equals(repeatDate)){
calendar.setTime(SHORT_DATE_FORMAT.parse(repeatDate));
}
} catch (ParseException e) {
e.printStackTrace();
}
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH)+1,calendar.get(Calendar.MINUTE));
return SHORT_DATE_FORMAT.format(calendar.getTime());
}