根据当期月获取上个月

private String getLastMonth(String currentDate) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    String lastDate = currentDate;
    try {
        date = sdf.parse(currentDate + "-" + "01");
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MONTH, -1);
        lastDate = new SimpleDateFormat("yyyy-MM").format(c.getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return lastDate;
}

你可能感兴趣的:(根据当期月获取上个月)