java 根据当前月的"yyyy-MM"获得上一个月“yyyy-MM”

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM”);
try {
String currentMonth = “2019-10”;
Date currentDate = sdf.parse(currentMonth);
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
System.out.println(sdf.format(calendar.getTime()));
} catch (ParseException e) {
e.printStackTrace();
}
}

猜你喜欢

转载自blog.csdn.net/qq_36912167/article/details/102624902