Java 获取下个月的今天

Date nowDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sdf.format(nowDate);
Date nextDate = getLastMonthDate(format);

private static Date getLastMonthDate(String dataTime) throws ParseException {
        //时间字符串转 LocalDate 类型
//        LocalDateTime today = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 转为自定义格式
        LocalDateTime today = LocalDateTime.parse(dataTime, dateTimeFormatter);
        //当前月份+(-1)
        today = today.minusMonths(-1);
        //LocalDate日期格式是"YYYY-MM-DD",只需要用toString()就可以转化成字符串类型
        return Date.from(today.atZone(ZoneId.systemDefault()).toInstant());

    }

你可能感兴趣的:(java,开发语言)