Java代码实现当前时间增加3个月

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

public class DateUtils {
    public static LocalDate addThreeMonths(LocalDate date) {
        // 使用TemporalAdjusters类将日期增加3个月
        return date.plusMonths(3).with(TemporalAdjusters.lastDayOfMonth());
    }

    public static void main(String[] args) {
        LocalDate currentDate = LocalDate.now();
        LocalDate newDate = addThreeMonths(currentDate);
        System.out.println("当前日期:" + currentDate);
        System.out.println("增加三个月后的日期:" + newDate);
    }
}

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