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代码实现当前时间增加3个月
最新推荐文章于 2023-11-30 11:10:38 发布