LocalDateTime取年月日
时间: 2023-11-28 10:44:24 浏览: 121
Java获取时间年、月、日的方法
5星 · 资源好评率100%
以下是使用LocalDateTime获取年月日的方法:
```java
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime localDateTime = LocalDateTime.now();
int year = localDateTime.getYear();
int month = localDateTime.getMonthValue();
int day = localDateTime.getDayOfMonth();
System.out.println("Year: " + year);
System.out.println("Month: " + month);
System.out.println("Day: " + day);
}
}
```
输出结果:
```
Year: 2021
Month: 10
Day: 20
```
阅读全文