import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class GetCurrentDate {
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") 用于指定日期的格式,这里我们使用 yyyy-MM-dd 格式。currentDate.format(formatter) 将当前日期按照指定的格式转换为字符串。如果你需要其他格式或功能,请告诉我!
上一篇:json转javabean
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站