java 獲取當前日期的下一月的當前日期

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());
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章