import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 将日期格式化为字符串
String formattedDate = currentDate.format(formatter);
// 输出结果
System.out.println("当前日期是: " + formattedDate);
}
}
java.time.LocalDate 来获取当前日期,并使用 java.time.format.DateTimeFormatter 来定义日期的输出格式。LocalDate.now() 方法可以获取当前的日期。DateTimeFormatter.ofPattern("yyyy-MM-dd") 来指定日期的输出格式为年-月-日的形式。currentDate.format(formatter) 将日期对象转换为指定格式的字符串。如果你需要其他帮助或有更多问题,请告诉我!
上一篇:java 获取当前日期0点
下一篇:java date设置指定日期
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站