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个月
最新推荐文章于 2024-12-13 10:18:23 发布
本文介绍了如何使用Java中的DateUtils类,特别是addThreeMonths方法,通过TemporalAdjusters类给给定的LocalDate对象增加三个月,并在最后一日进行调整。主函数展示了如何在控制台上打印当前日期和增加三个月后的日期。

3191

被折叠的 条评论
为什么被折叠?



