1、当前日期的下一月的当前日期 private static String getLastMonthDate(String dataTime) throws ParseException { //时间字符串转 LocalDate 类型 LocalDate today = LocalDate.parse(dataTime); //当前月份+(-1) today = t
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();
}
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());
}
【感谢龙石为本站提供数据底座技术支撑http://www.longshidata.com/pages/government.html】