import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 当前日期加一天
LocalDate nextDay = currentDate.plusDays(1);
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 打印结果
System.out.println("当前日期: " + currentDate.format(formatter));
System.out.println("加一天后的日期: " + nextDay.format(formatter));
}
}
这段代码展示了如何使用 Java 的 LocalDate 类来获取当前日期,并通过 plusDays(1) 方法将日期加一天。最后,使用 DateTimeFormatter 来格式化输出日期。
上一篇:java 获取文件名
下一篇:java class文件
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站