用java获取今天的日期
时间: 2023-07-18 10:14:11 浏览: 40
可以使用Java中的日期时间类库获取今天的日期,以下是获取今天日期的代码示例:
```java
import java.time.LocalDate;
public class GetTodayDate {
public static void main(String[] args) {
LocalDate today = LocalDate.now();
System.out.println("Today's date is: " + today);
}
}
```
运行上述代码将输出当前日期,例如:`Today's date is: 2022-01-01`。
相关问题
java获取今天日期, 年月日
您好,今天的日期是2022年2月2日。要获取当前日期,可以使用Java中的Date类或Calendar类。以下是使用Calendar类获取当前日期的示例代码:
```
import java.util.Calendar;
public class GetCurrentDate {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println("今天的日期是: " + year + "年" + month + "月" + day + "日");
}
}
```
输出结果:
```
今天的日期是: 2022年2月2日
```
java获取今天的日期
今天的日期可以通过以下代码获取:
```java
import java.time.LocalDate;
LocalDate today = LocalDate.now();
System.out.println("今天的日期是:" + today);
```
输出结果类似于:
```
今天的日期是:2021-10-21
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)