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);
}
}
LocalDate.now():获取系统当前的日期,不包含时间部分。DateTimeFormatter.ofPattern("yyyy-MM-dd"):定义日期的格式为 年-月-日 的形式。currentDate.format(formatter):将 LocalDate 对象格式化为指定格式的字符串。System.out.println():输出格式化后的当前日期。下一篇:java调用python程序
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站