LocalDate with
时间: 2023-10-15 21:24:59 浏览: 70
Yes, you can use the `LocalDate` class in Java to work with dates without time or time zone information. It is part of the `java.time` package introduced in Java 8.
To create a `LocalDate` object, you can use the static `of` method, passing in the year, month, and day as arguments. Here's an example:
```java
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date = LocalDate.of(2022, 10, 31);
System.out.println(date); // Output: 2022-10-31
}
}
```
You can also get the current date using the `now` method:
```java
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate currentDate = LocalDate.now();
System.out.println(currentDate); // Output: current date in yyyy-mm-dd format
}
}
```
Once you have a `LocalDate` object, you can perform various operations on it, such as getting the day of the week, adding or subtracting days, months, or years, comparing dates, and formatting dates.
阅读全文