import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class GetCurrentDate {
public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
System.out.println("当前日期: " + currentDate);
// 如果需要格式化输出日期,可以使用 DateTimeFormatter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedDate = currentDate.format(formatter);
System.out.println("格式化后的当前日期: " + formattedDate);
}
}
LocalDate.now(): 用于获取当前系统的日期,返回一个 LocalDate 对象。DateTimeFormatter: 用于格式化日期。通过 ofPattern("yyyy-MM-dd") 指定日期的格式为年-月-日。format(): 将 LocalDate 对象按照指定的格式转换为字符串。这段代码展示了如何获取当前日期并进行格式化输出。
上一篇:java string转json
下一篇:java动态代理
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站