java如何获取当前年月日

443
2023/8/3 1:24:16
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Java中,可以使用java.time包中的LocalDate类来获取当前年月日。以下是一个示例代码:

import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate currentDate = LocalDate.now();
int year = currentDate.getYear();
int month = currentDate.getMonthValue();
int day = currentDate.getDayOfMonth();
System.out.println("当前年月日:" + year + "-" + month + "-" + day);
}
}

运行以上代码,将输出当前年月日。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: java中native方法如何查看